Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Push to an array in a hash of hashes

by kennethk (Abbot)
on Aug 07, 2013 at 21:44 UTC ( #1048442=note: print w/replies, xml ) Need Help??


in reply to Push to an array in a hash of hashes

You missed with your curlies; you are going to store an array reference in $hoh{'word'}{'array'}, and then dereference that, so curlies go around the whole expression.
use strict; use warnings; use 5.10.0; my %hoh; my @arr = ('first', 'second', 'third'); push (@{$hoh{'word'}{'array'}}, @arr); #now good $hoh{'word'}{'count'} += 1; $hoh{'word'}{'count'} += 1; say "The count of 'word' is ", $hoh{'word'}{'count'}; say "The array of 'word' is @{$hoh{'word'}{'array'}}"; # now good.

See perlreftut and/or perllol. Note also I moved your array into the double quotes, so it interpolates w/ spaces (by default).


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: Push to an array in a hash of hashes
by BillKSmith (Priest) on Aug 08, 2013 at 01:45 UTC
    Note: The pertinent default is the value of the special variable LIST_SEPARATOR ($").
    Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048442]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2016-12-03 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (56 votes). Check out past polls.