in reply to Re: Use of uninitialized value $1
in thread Use of uninitialized value $1
$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: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Use of uninitialized value $1
by Marshall (Canon) on Aug 25, 2016 at 19:15 UTC | |
by AnomalousMonk (Archbishop) on Aug 26, 2016 at 01:06 UTC | |
by Marshall (Canon) on Aug 26, 2016 at 03:15 UTC |