Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Push onto arrays in a hash?

by cardozo (Novice)
on Dec 23, 2002 at 16:46 UTC ( #221893=perlquestion: print w/replies, xml ) Need Help??
cardozo has asked for the wisdom of the Perl Monks concerning the following question:

I want to have a hash of arrays, onto which I can push elements.

I realize that the 'arrays' in the hash aren't really arrays, but are references to anonymous arrays. (at least I think I realize that.)

What I wanted to do was:

push ($HOA{'bar'}, 'foo');

But that incantation didn't work.

I can't build the array and then put it in the hash because I'm dealing with lots of data, and elements that should be pushed onto any of the thousand (or so) arrays could come in any order.

Any ideas?

Replies are listed 'Best First'.
Re: Push onto arrays in a hash?
by BrowserUk (Pope) on Dec 23, 2002 at 16:51 UTC

    Try

    push ( @{$HOA{'bar'}}, 'foo');

    Examine what is said, not who speaks.

Re: Push onto arrays in a hash?
by Nitrox (Chaplain) on Dec 23, 2002 at 16:56 UTC
    From perldsc:
    push @{ $HoA{"flintstones"} }, "wilma", "betty";

    -Nitrox

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://221893]
Approved by zigdon
Front-paged by jdporter
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2018-08-18 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (186 votes). Check out past polls.

    Notices?