Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl hashes: is there some way of adding more data to the value associated with an existing key?

by Eliya (Vicar)
on Jun 07, 2011 at 14:53 UTC ( [id://908491]=note: print w/replies, xml ) Need Help??


in reply to Perl hashes: is there some way of adding more data to the value associated with an existing key?

The value of a hash entry is a scalar, but this scalar can be a reference to an array, into which you can put more than one value:

push @{ $hash{$id} }, $val;

Also, Perl features autovivification, so you don't need to worry about the initial case when there is no array(ref) yet — i.e. Perl implicitly creates it for you.

  • Comment on Re: Perl hashes: is there some way of adding more data to the value associated with an existing key?
  • Download Code

Log In?
Username:
Password:

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

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

    No recent polls found