Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: How to build a hash?

by Jasper (Chaplain)
on Apr 25, 2005 at 12:31 UTC ( #451156=note: print w/ replies, xml ) Need Help??


in reply to Re: How to build a hash?
in thread How to build a hash?

No, like an array element ($array[$n]) the accessor of a hash element ($hash{'foo'}) is also an lvalue (basically you can assign a value to it). This method of accessing or modifying one value at a time doesn't affect the rest of the hash.

You can also modify several elements at once using a hash slice, for example

@hash{'foo','bar','baz'} = (1,2,3);
Only when you say %hash are you definitely effecting the entire hash.
%hash = ('foo',1,'bar',2'baz',3); # whole hash overwritten $hash{foo} = 1; # only one element created or modified @hash{@array} = (1,2,3); # only elements specified in @array overwritt +en, or created.


Comment on Re^2: How to build a hash?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2015-07-29 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls