Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Strange Regex Behavior

by remiah (Hermit)
on Dec 06, 2011 at 07:04 UTC ( [id://941966]=note: print w/replies, xml ) Need Help??


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...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://941966]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-23 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found