Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Find and Replace Howto

Reply
Thread Tools

Find and Replace Howto

 
 
Anuradha
Guest
Posts: n/a
 
      08-18-2003
Hi,

I am newbie to Perl and would like to know if this possible doing in
Perl.

I have huge number of .4gl files. I need to find and replace the
string which contains mySchema.TO_CHAR( to CHAR( .

This can be accomplished in one-liner. While the problem I am facing
is
mySchema.TO_CHAR() is overloaded with arguments. I need to replace
ones which does not have ',' to TO_CHAR(). Here also care should be
taken that
TO_CHAR ( SUBSTR()) can also be done. so while searching it should
handle this also.

Any idea if this can be done in Perl or better do it manually.

Let me know and thanks for reading this query.

Anu
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      08-18-2003
Anuradha wrote:
> I have huge number of .4gl files. I need to find and replace the
> string which contains mySchema.TO_CHAR( to CHAR( .
>
> This can be accomplished in one-liner. While the problem I am
> facing is mySchema.TO_CHAR() is overloaded with arguments. I need
> to replace ones which does not have ',' to TO_CHAR(). Here also
> care should be taken that TO_CHAR ( SUBSTR()) can also be done. so
> while searching it should handle this also.
>
> Any idea if this can be done in Perl or better do it manually.


I'm convinced it can be done in Perl, and if the number of files is
"huge", it is probably advisable.

http://www.perldoc.com/perl5.8.0/pod...#Files-and-I-O

http://www.perldoc.com/perl5.8.0/pod/perlre.html

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
 
Simon Taylor
Guest
Posts: n/a
 
      08-19-2003
Anuradha wrote:

> I am newbie to Perl and would like to know if this possible doing in
> Perl.
>
> I have huge number of .4gl files. I need to find and replace the
> string which contains mySchema.TO_CHAR( to CHAR( .
>
> This can be accomplished in one-liner. While the problem I am facing
> is
> mySchema.TO_CHAR() is overloaded with arguments. I need to replace
> ones which does not have ',' to TO_CHAR(). Here also care should be
> taken that
> TO_CHAR ( SUBSTR()) can also be done. so while searching it should
> handle this also.
>
> Any idea if this can be done in Perl or better do it manually.
>
> Let me know and thanks for reading this query.
>
> Anu


Hello Anu,

When I've dealt with transformations like this I first consider whether
or not the data that needs to be transformed will always
appear in some regular (and trivial) pattern, or whether it may indeed
appear in any pattern that is legally acceptable to the program that was
designed to read it.

What I mean by this is if you have lines that are all of the format:

mySchema.TO_CHAR(12)
mySchema.TO_CHAR(12, 2)
mySchema.TO_CHAR(substr(blah, blah), 10, 2)

then regular expressions may be the best solution


However, if the data is more variable:

mySchema.TO_CHAR(
12
)
other(things) that are
unrelated('mySchema').....
mySchema.TO_CHAR( -- oops a legal SQL comment?
12);
mySchema.TO_CHAR
(12, 2)
mySchema.TO_CHAR(
substr(blah
, blah), 10, 2)

then it may pay you to build a little parser to process the data.

It can be difficult working out how to strike a good balance between
these two approaches.

However in my experience doing similar transformations, the input is
usually rather orderly and lends itself well to transformation via
simple regular expressions.

Why don't you follow up this post with a small sample of the existing
data, *exactly* as it appears in the ".4gl" file, and how this data
should be transformed.

Hope this helps,

Simon Taylor






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
Re: [Pyrex] pyrex functions to replace a method (Re: replace a method Greg Ewing Python 2 06-29-2006 05:25 PM
pyrex functions to replace a method (Re: replace a method in class:how?) Brian Blais Python 1 06-27-2006 12:13 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM



Advertisments