in reply to Re: reading/writing line by line
in thread reading/writing line by line

I fear this is an especially dumb question, but here goes...

I've seen a lot of people recommending the "perl -i" solution for regexes, like your
perl -i.backup -pe 's/foo/bar/g' filename
Can that be used for multiple regexes in a file? Like, if you wanted to do s/foo/bar/g and s/y/yah/g on the same file?

Replies are listed 'Best First'.
Re: Re: Re: reading/writing line by line
by amarceluk (Beadle) on May 22, 2002 at 19:42 UTC
    I rescind the question. Yes, it's dumb, and yes, I figured it out by doing a search for "perl -i". Sorry.
Re: Re: Re: reading/writing line by line
by Juerd (Abbot) on May 22, 2002 at 19:44 UTC

    Can that be used for multiple regexes in a file? Like, if you wanted to do s/foo/bar/g and s/y/yah/g on the same file?

    Yes. See what happens if you use just perl -pe'undef':

    LINE: while (defined($_ = <ARGV>)) { undef; } continue { die "-p destination: $!\n" unless print $_; }
    So you can just add whatever should be inside the block:
    perl -i -pe's/foo/bar/g; s/y/yah/g;' filename

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      Thank you! I figured there had to be a way to do it but it wasn't intuitively obvious.