$1, $2.. etc are weird variables. ... they disappear when ... a new regexp is encountered. [Emphasis Added]
Even more weird! These variables keep their value until a new regex is successfully matched or dynamic scope is exited.
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $str = 'foo--bar'; dd $1, $2; ;; $str =~ m{ (foo) .* (bar) }xms; print qq{A: \$1 '$1' \$2 '$2'}; ;; $str =~ m{ (x) .* (y) }xms; print qq{B: \$1 '$1' \$2 '$2'}; " (undef, undef) A: $1 'foo' $2 'bar' B: $1 'foo' $2 'bar'
Give a man a fish: <%-{-{-{-<
In reply to Re^2: Use of uninitialized value $1
by AnomalousMonk
in thread Use of uninitialized value $1
by Pazitiff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |