in reply to String substitution
Also, a couple notes on your code... $_ is aliased to each element of your array when using map or a for loop, so there's no need to do something like @lines = map { s/...//; $_ } @lines; ... You can just say s/...// for @lines;
If you're reading and writing to the same file, you can use the -i option on the command line. So you could probably shorten your entire code to this:
perl -pi.bak -e 's/apple/orange/gi' c:\data
This will overwrite your original file, substituting 'apple' with 'orange' wherever it is found, and will make a backup copy with a .bak extension in case that's not what you wanted.
-- Mike
--
just,my${.02}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: String substitution
by Anonymous Monk on Aug 09, 2006 at 19:59 UTC | |
by ikegami (Patriarch) on Aug 09, 2006 at 20:36 UTC | |
|
Re^2: String substitution
by Anonymous Monk on Aug 11, 2006 at 17:23 UTC |