Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl: the Markov chain saw
 
PerlMonks  

RE: Re: Using an array in a hash

by BlaisePascal (Monk)
on Aug 08, 2000 at 00:51 UTC ( [id://26714]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Using an array in a hash
in thread Using an array in a hash

To elaborate on that second part...

When you say %hash = (a => "foo", b => "bar") perl treats the "=>" operator as a synonym for ",", so this really looks like %hash = (a,"foo",b,"bar"). Perl knows to treat a list assigned to a hash as key/value pairs, so this works right.

In your example, where you tried %hash = (a => (foo,bar, baz)), perl treats the right hand side as (a,(foo,bar,baz)), which is "flattened" into (a,foo,bar,baz), which is then assigned to %hash, yielding %hash{a} = "foo" and %hash{bar} = "baz", which isn't what you wanted.

The suggestions to use references will do what you want.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://26714]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.