> -Original Message-
> You can do it right at the command line...
>
> ** make a backup of the file first just in case!! **
>
> perl -pi -e "s|replace this text|with this text|g" somefile.txt
>
Why make a backup FIRST? Try this...
perl -pi.bak -e "s|this|that|igo" somefile.txt
LEGAL N
>You can do it right at the command line...
Now why would we want do to something that fast & easy?! ;)
Lee
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
You can do it right at the command line...
** make a backup of the file first just in case!! **
perl -pi -e "s|replace this text|with this text|g" somefile.txt
It will open somefile.txt, run the regex on each line of the file, and
replace the current file with the updated text.
Take a look at t
Lee Clemmer <[EMAIL PROTECTED]> wrote:
>> s/$search/$newstr/i
>You might want to modify this to
>s/$search/$newstr/igo
Ah, I realized after I sent it that "greedy" wasn't set. Oops. But I
didn't know about the "o", though.
>The "o" promises Perl you will never change the $search string. Perl
Lee Clemmer <[EMAIL PROTECTED]> wrote:
> s/$search/$newstr/i
You might want to modify this to
s/$search/$newstr/igo
The "o" promises Perl you will never change the $search string. Perl will
then put it through the regular expression compiler the first time it's
encountered, and you _should_ pe
Here's one way to do it. The code is readable versus efficient.
Note that this preserves the original file in case you screw up.
#!/usr/bin/perl -w
# search and replace
my ($search, $newstr, $file, $temp, $counter);
usage() unless scalar(@ARGV) >= 1;
print "Pattern to search for: ";
chomp($sea