in reply to search pattern with digits
You are looking for two different things so you need to have two alternations
or using perl 5.10my $reject_rx = qr{ total [ ] rows [ ] rejected: [ ] (\d+) | (\d+) [ ] rows [ ] rejected }x; if ( $line =~ /$reject_rx/ ) { my $count = defined $1? $1 : $2; print $count, "\n"; }
the /x means that white space is ignored and comments can be put in. That is why I had to put to match a literal space.use 5.010_00 my $reject_rx = qr{ (?| # either match will be in $1 total [ ] rows [ ] rejected: (\d+) | (\d+) [ ] rows [ ] rejected ) }x; if ( my ($count) = $line =~ /$reject_rx/ ) { say $count; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search pattern with digits
by mercuryshipz (Acolyte) on Feb 14, 2008 at 20:12 UTC | |
by hipowls (Curate) on Feb 14, 2008 at 20:35 UTC | |
by mercuryshipz (Acolyte) on Feb 14, 2008 at 21:07 UTC | |
by hipowls (Curate) on Feb 14, 2008 at 22:22 UTC |