in reply to One-shot code critique
with$text =~ s/$target/$replace/; $text =~ s/$target2/$replace/;
$text =~ s/$target/$replace/i; # Case-insensitive
Second, I'd look at letting Perl's -i and -p flags do all your editing in place for you. It takes care of all the globbing, the reading the file, etc etc etc.
For instance, your code could simply be (rough and untested):
And you'd just call it as:#!perl -i~ -p BEGIN { $/ = undef; $target = blah blah blah; $replace = blah blah blah; } s/$target/$replace/ig;
myprog.pl *.asp
Perl has some very powerful, very common idioms to do this most common of text transformations. Take advantage of them when you can.
xoxo,
Andy
--
<megaphone>
Throw down the gun and tiara and come out of the float!
</megaphone>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use Perl's in-place file-handling capabilities
by patgas (Friar) on Sep 28, 2001 at 20:50 UTC |