in reply to Re: Strange Regex Behavior
in thread Strange Regex Behavior

I saw the same outputs in my perl 5.12.3. It seems perl confusing for $1 because this also prints "100" without warnings;

%hash =( a => ($b =~ /(\d+)/ ? $1 : 0), b => "test b", ); print "$_=#$hash{$_}#\n" for keys %hash;

And named capture seems to work fine.

%hash = ( a => (($b =~ /(?<tag>\d+)/) ? $+{tag} : 0), b => (($b =~ /(?<tag>test)/) ? $+{tag} : 0), ); print "$_=#$hash{$_}#\n" for keys %hash;

But I have no idea for why named capture doesn't confuse...