Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Hash Syntax Question

by FunkyMonk (Chancellor)
on Jul 25, 2007 at 20:11 UTC ( [id://628777]=note: print w/replies, xml ) Need Help??


in reply to Hash Syntax Question

Yes, there's a difference. $hash{OneWord} is OK, but $hash{Two Words} is a syntax error.

From perldata (emphasis mine):

In fact, an identifier within such curlies is forced to be a string, as is any simple identifier within a hash subscript. Neither need quoting. Our earlier example, $days{'Feb'} can be written as $days{Feb} and the quotes will be assumed automatically. But anything more complicated in the subscript will be interpreted as an expression. This means for example that $version{2.0}++ is equivalent to $version{2}++ , not to $version{'2.0'}++
So, if it looks like an identifier, you don't need to quote it.

Replies are listed 'Best First'.
Re^2: Hash Syntax Question
by Anonymous Monk on Jul 25, 2007 at 20:54 UTC
    also be aware of the following little gotcha:

    perl -wMstrict -e "my %h; $h{shift} = 'foo'; print %h" bar shiftfoo perl -wMstrict -e "my %h; $h{shift()} = 'foo'; print %h" bar barfoo
Re^2: Hash Syntax Question
by BarMeister (Beadle) on Jul 25, 2007 at 20:21 UTC
    ok thanks that was very helpful :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found