in reply to Bug? Use of uninitialized value $1 in substitution iterator

Perl distinguishes between a capture that wasn't encountered in the match and a capture that matched zero characters.
use Data::Dumper qw( Dumper ); '' =~ / ^ ( (?: ( bb ) # $2 )? ) # $1 $ /x; local $Data::Dumper::Useqq = 1; local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 0; print('$1 = ', Dumper($1), "\n"); print('$2 = ', Dumper($2), "\n");
$1 = "" $2 = undef

Replies are listed 'Best First'.
Re^2: Bug? Use of uninitialized value $1 in substitution iterator
by clinton (Priest) on Mar 04, 2009 at 18:29 UTC
    nicely explained