On Fri, 13 Jul 2001, Assaf Spanier wrote:

> Hi I'm trying to replace the string 'aaa' to 'bbb' in my files
> the fallowing scrip DO NOT do the job, If anyone can tell me
> where is my mistake, I will be grateful.
>
> ---------------------------
> !/usr/bin/perl -w
>
>
> open OUT, "+</tmp/file" or die "Can't open /tmp/file \n";
>
> while (<OUT>) {
>   $_ =~ s/aaa/bbb/g;
> }
>   close OUT;
> ----------------------------------

You're not writing the changed line back out.  You can't directly edit a
file in place -- you will need to create a temp file and write your
changes out there, and then copy it to the original file name, or use the
-i command line option.  In fact, this snippet of code can easily be
reduced to a Perl one liner:

perl -pi.bak -e 's/aaa/bbb/g' /tmp/file

-- Brett
                                   http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Good judgement comes from experience.  Experience comes from bad judgement.
                -- Jim Horning


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to