in reply to Pattern matching with a variable
Regular expressions take time to compile, so you want to avoid putting dynamic regexps in a tight loop.$library = [contents of library.txt] $input = [contents of input.txt] my %in_library = (); foreach $entry (split(/\n/, $library)) { $in_library{"$entry"} = 1; } my @input = split(/\n/, $input); foreach $entry (@input) { if ($in_library{"$entry"}) { print "found - $entry\n"; } else { print "new - $entry\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pattern matching with a variable
by Ytrew (Pilgrim) on Nov 04, 2004 at 17:08 UTC |