in reply to file substitution
I am not sure on performance, as I have not implemented something like this, but...
How about something like this....
... my @junk = map {chomp $_; qr(\Q$_\E)} <JUNK>; while (<>) { # Added / Modified my $line = $_; next if $line =~ $_ foreach (@junk); # End update print; }
Order the junkfile in descending order of occurances.
Another option, to avoid the inner loop, would be to build a giant alternation regexp (qr((foo|bar|biz|bang))) from the junk file. However, then you need to escape various things. In addition, I am not sure which is faster, the alternation regexp or the nested loop.
--MidLifeXis
P.S. All code is untested, blah blah blah.
Update: Updated foreach stuff - Thanks BrowserUk. Added \Q..\E. Thanks Berik.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: file substitution
by BrowserUk (Patriarch) on Jun 04, 2004 at 18:56 UTC | |
|
Re^2: file substitution
by Berik (Sexton) on Jun 04, 2004 at 18:46 UTC |