How to replace a "/" in perl

Discussion in 'Perl Misc' started by chunji08@gmail.com, Feb 20, 2007.

  1. Guest

    I have a list of sql files, in which it ends with a "/". Now I want to
    replace it with "//end" for all files. And here is my perl command,
    "
    perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
    "

    Suprisingly it does not work. Does someone know how to make it
    working ?

    I am using perl 5.6.1 on Linux.


    Charlie
    , Feb 20, 2007
    #1
    1. Advertising

  2. wrote in news:1172009738.829363.189370
    @v45g2000cwv.googlegroups.com:

    > I have a list of sql files, in which it ends with a "/". Now I want to
    > replace it with "//end" for all files. And here is my perl command,
    > "
    > perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
    > "
    >
    > Suprisingly it does not work.


    It does not work is a bad description. Please read the posting
    guidelines for this group.

    #!/usr/bin/perl

    use strict;
    use warnings;

    while ( <DATA> ) {
    s{^/$}{//end} and print;
    }

    __DATA__
    /
    /
    /
    /
    /
    /
    /

    Sinan
    A. Sinan Unur, Feb 20, 2007
    #2
    1. Advertising

  3. On Feb 20, 2:15 pm, wrote:
    > I have a list of sql files, in which it ends with a "/". Now I want to
    > replace it with "//end" for all files. And here is my perl command,
    > "
    > perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL



    * if you add -w to the options, you'll
    get a fatal syntax error,

    perl -pi.org -we ...

    * you don't want the ^ on the left-hand side

    for regular expression help, see:

    perldoc perlrequick
    perldoc perlretut

    * use alternative substitution delimiter to
    avoid backslash-itis, eg.,

    s{something}{for something else}

    --
    Charles DeRykus
    comp.llang.perl.moderated, Feb 20, 2007
    #3
  4. Guest

    On Feb 20, 2:43 pm, "A. Sinan Unur" <> wrote:
    > wrote in news:1172009738.829363.189370
    > @v45g2000cwv.googlegroups.com:
    >
    > > I have a list of sql files, in which it ends with a "/". Now I want to
    > > replace it with "//end" for all files. And here is my perl command,
    > > "
    > > perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
    > > "

    >
    > > Suprisingly it does not work.

    >
    > It does not work is a bad description. Please read the posting
    > guidelines for this group.
    >
    > #!/usr/bin/perl
    >
    > use strict;
    > use warnings;
    >
    > while ( <DATA> ) {
    > s{^/$}{//end} and print;
    >
    > }
    >
    > __DATA__
    > /
    > /
    > /
    > /
    > /
    > /
    > /
    >
    > Sinan


    My Fault.
    The correct answer should be:
    "
    perl -pi.org -e 's/^\/$/\/\/end/' *.SQL
    "

    C
    , Feb 20, 2007
    #4
    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:
    374
    Bruno Desthuilliers
    Jun 27, 2006
  2. Greg Ewing
    Replies:
    2
    Views:
    342
    Dieter Maurer
    Jun 29, 2006
  3. Alun
    Replies:
    3
    Views:
    4,496
    Masudur
    Feb 18, 2008
  4. Prasad S
    Replies:
    2
    Views:
    226
    Dr John Stockton
    Aug 27, 2004
  5. lucy
    Replies:
    7
    Views:
    183
    Joe Smith
    Sep 3, 2004
Loading...

Share This Page