Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Strange Regex Behavior

by vinian (Beadle)
on Dec 06, 2011 at 10:01 UTC ( [id://941983]=note: print w/replies, xml ) Need Help??


in reply to Strange Regex Behavior

It seems match the last 'key => value' first, i try the below code serval times, but got the same output.

use strict; use warnings; use Data::Dumper; my $b = 'test 200'; my %hash = ( c => ( $b =~ /([a-z]+)/ ? $& : 0 ), b => ( $b =~ /(\d+)/ ? $` : 0 ), a => ( $b =~ /\s+/ ? $' : 0 ), ); print Dumper(\%hash);

Output:

$VAR1 = { 'c' => ' ', 'a' => '200', 'b' => 'test' };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found