if you just need the exception lines:#!/usr/bin/perl -w use strict; use Data::Dumper; my @strings = qw(exception:tex exception:mex exception:mex asdf tex:exception:mex asdf exception:mex asdf asdf exception:mex); foreach (1..4) { my @filtered = grep { /exception:/ && !/mex/ } @strings; print Dumper(\@filtered); } __END__ prints: $VAR1 = [ 'exception:tex' ]; $VAR1 = [ 'exception:tex' ]; $VAR1 = [ 'exception:tex' ]; $VAR1 = [ 'exception:tex' ];
#!/usr/bin/perl -w use strict; use Data::Dumper; my @strings = qw(exception:tex exception:mex exception:mex asdf tex:exception:mex asdf exception:mex asdf asdf exception:mex); foreach (1..4) { my @filtered = grep { /exception:/ } @strings; print Dumper(\@filtered); } __END__ prints: $VAR1 = [ 'exception:tex', 'exception:mex', 'exception:mex', 'tex:exception:mex', 'exception:mex', 'exception:mex' ]; ...3 more of same
In reply to Re: strange behavior of grep with global match
by Marshall
in thread strange behavior of grep with global match [resolved]
by ig
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |