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

Re: Hash Key vs. Quantifier Ambiguity in Regex Context

by jarich (Curate)
on Apr 01, 2004 at 00:08 UTC ( [id://341468]=note: print w/replies, xml ) Need Help??


in reply to Hash Key vs. Quantifier Ambiguity in Regex Context

(2) You can see that Perl chooses (a) for /$x{1}/. If I want (b), is there a better way than @{[$x{1}]}[0]?

Absolutely. Quote your hash key.

my $x = "(quantifier)"; my %x = ( "1" => "(hash_value)" ); my $z = 'quantifier hash_value'; print "_$1_\n" if $z =~ /$x{'1'}/; # $x{'1'} is hash key __END__ _hash_value_

Hope this helps.

jarich

Replies are listed 'Best First'.
Re: Re: Hash Key vs. Quantifier Ambiguity in Regex Context
by QM (Parson) on Apr 01, 2004 at 00:24 UTC
    Thanks! [Seems I've left my Obvious Hat at home today :( ]

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

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

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

    No recent polls found