Find and Replace Howto

Discussion in 'Perl Misc' started by Anuradha, Aug 18, 2003.

  1. Anuradha

    Anuradha Guest

    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
     
    Anuradha, Aug 18, 2003
    #1
    1. Advertising

  2. 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/perlintro.html#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
     
    Gunnar Hjalmarsson, Aug 18, 2003
    #2
    1. Advertising

  3. Anuradha

    Simon Taylor Guest

    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
     
    Simon Taylor, Aug 19, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Blais
    Replies:
    1
    Views:
    383
    Bruno Desthuilliers
    Jun 27, 2006
  2. Greg Ewing
    Replies:
    2
    Views:
    347
    Dieter Maurer
    Jun 29, 2006
  3. Wybo Dekker
    Replies:
    1
    Views:
    368
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    417
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    818
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page