### Code Snippet @array = ('<Band:3>40M <Call:5>KD4RR <QSL_Rcvd:1>Y <QSL_Sent:1>Y', '<Band:3>40M <Call:5>K7RRR <QSL_Sent:1>Y', '<Band:3>40M <Call:5>W7FAL <QSL_Rcvd:1>Y <QSL_Sent:1>Y'); my $num_elements = @array; my $counter = 0; while ($counter < $num_elements) { $array[$counter] =~ /(QSL_RCVD:|QSL_Rcvd:)(\d+)>(\w+)/; if ($3 eq "Y") { print "Good Record: $array[$counter]\n"; $counter++ } else { print "Bad Record: $array[$counter]\n"; $counter++ } }
Problem Description: When I run the above code,
I would expect the 2nd element in the array to
be printed as a bad record, as there is not a match
for the pattern being searched for (it doesn't have a
QSL_Rcvd field). However, it appears the pattern is
matched and it is printed as a good record. If I
re-arrange the order of the elements in the array,
and put the second element as the first element, then
the code works as I expected and the first element
is printed as a bad record.
From observation it looks like there is some kind of
persistence in $3, but that seems unlikely, so I am
thinking the problem is somehow related to my search
expression. Any help or insight would be appreciated.
In reply to Problem with regexp or saved match variable. by steve077
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |