in reply to Re^2: Comparing pattern
in thread Comparing pattern
Now I have this code but I'm facing a new problem. In my first example I use both flags /is I need /s so . to match newlines as well. I have thisuse Regexp::Assemble; my $patterns = "/path/to/file.txt"; my $list_regex = Regexp::Assemble->new(file => $patterns); $list_regex->track( 1 ); open( FILE, "<", "$arg1") or die "$arg1: $!\n"; while (<FILE>) { if (/$list_regex/) {print "\n$arg1\n$list_regex->matched\n";} } close(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 $regexStr = "(" . join("|", @list_patterns) . ")"; my $list_regex = qr{$regexStr}i; open( FILE, "<", "$arg1") or die "$arg1: $!\n"; while (<FILE>) { if (/$list_regex/) {print "\n$arg1\n$1\n";} } close(FILE);
This pattern working with my original script. .* should match also newline.part1.*part2
This is the last problem, else the script working perfectly and much faster thanks to your advices. I will next take a look at local $/.fggffgfg part1 hghggh ghhggh hggh part2 ytyty
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Comparing pattern
by graff (Chancellor) on Sep 19, 2009 at 13:42 UTC |