in reply to Comparing pattern
If your list of patterns does not include anything that tries to match across a line-break (i.e.: "...\n..."), then you don't need to slurp your whole "arg1" file content into memory at one time. Depending on the files that you are searching through, that can save time by avoiding memory swaps, and depending on what sort of patterns you are looking for, applying the regex to a small string (one line at a time) could be a lot faster than applying it to a whole file.my $patterns = "/path/to/file.txt"; my $arg1 = shift; open( PATTERNS, "<", $patterns ) or die "$patterns: $!\n"; my @list_patterns = <PATTERNS>; close PATTERNS; chomp @list_patterns; my $list_regex = join '|', @list_patterns; open( FILE, "<", $arg1 ) or die "$arg1: $!\n"; while (<FILE>) { if ( /($list_regex)/ ) { print "\n$arg1\n$1\n"; } }
If your patterns do involve matching across line breaks, loading them all into a single regex (joining them together with "|") will probably speed things up anyway, because you only do one regex match against the whole string.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing pattern
by mrc (Sexton) on Sep 19, 2009 at 07:57 UTC | |
by mrc (Sexton) on Sep 19, 2009 at 10:15 UTC | |
by graff (Chancellor) on Sep 19, 2009 at 13:42 UTC | |
|
Re^2: Comparing pattern
by LanX (Saint) on Sep 19, 2009 at 11:31 UTC | |
|
Re^2: Comparing pattern
by mrc (Sexton) on Sep 20, 2009 at 18:27 UTC | |
by graff (Chancellor) on Sep 20, 2009 at 19:16 UTC | |
by mrc (Sexton) on Sep 21, 2009 at 05:13 UTC | |
by graff (Chancellor) on Sep 22, 2009 at 00:32 UTC | |
by mrc (Sexton) on Sep 24, 2009 at 09:32 UTC | |
by mrc (Sexton) on Sep 26, 2009 at 10:33 UTC |