in reply to Altering an array with grep & map
You mean prepend, by your code.
You don't neeed to slurp the whole file if you're operating on separate lines anyway.
grep acts as a filter and returns a list containing only things for which BLOCK evaluated true. If I understand what you're trying to do, then (apart from the fact that you aren't calling grep correctly in terms of syntax, because you aren't feeding it the LIST you are supposed to), you are also using it wrong because it will weed out lines that didn't contain "links".
If you just use line mode, and take advantage of the fact that substitutions fail silently, you can just do this:
open my $fh, "<file.htm" or die "open: $!"; while (<$fh>) { s{(href|src)="}{$1="../}g; print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Altering an array with grep & map
by JayBee (Scribe) on Jan 18, 2005 at 23:50 UTC | |
by gaal (Parson) on Jan 19, 2005 at 09:03 UTC |