Hi
in scripts I usually match like this:
my ($match) = $string =~ /$regex/;
but sometimes I do one-liners like this:
perl -ne '/$regex/, $SUM += $1; END { print $SUM }' file.txt
In this context I was just bitten by the (documented) behaviour that a failed match does not reset the match variables which in my case lead to a wrong sum as on empty lines where the regex did not match the previous match was (again) added to the sum.
For curiosity's sake now:
Assuming I did not want to introduce new variables but use $1 etc: How would I reset these variables to avoid the wrong sum as both "undef $1" as "$1=undef" does not work?