Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Is it possible to use key/values of a Hash/Hash ref while it's being initialized?

by ikegami (Patriarch)
on Sep 14, 2005 at 20:04 UTC ( [id://491997]=note: print w/replies, xml ) Need Help??


in reply to Is it possible to use key/values of a Hash/Hash ref while it's being initialized?

Yes:

my %hash; $hash{key1} = 'longstring'; $hash{key2} = alter($hash{key1});

Admittedly, you have to change your initialization syntax somewhat. The reason is that list on the right hand side of the = is built before the assignment even starts. (See perlop for operator precedence.) Some people seem to think %h = (a=>b, c=>d); is a hash constructor/initializer, but it's not. It's simply a list which gets assigned to a hash.

Replies are listed 'Best First'.
Re^2: Is it possible to use key/values of a Hash/Hash ref while it's being initialized?
by shiza (Hermit) on Sep 14, 2005 at 20:25 UTC
    /me goes to delve into perlop. Thanks!

Log In?
Username:
Password:

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

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

    No recent polls found