in reply to How can I push a hash onto an array?
What you need to do is push a reference to the hash into the array. see perlman:perlref for details on references, but basically a reference is something that points to something rather than being the thing. If you know C, then it's a pointer that does what you always thought pointers should : ) If not, than it is a scalar which holds a value that points to where perl can find something else like a hash.
references can be simple like:
use strict; # or DIE : ) use warnings; # or SUFFER : ) my %hash = { one => 'this', two => 'that' }; my $reference = \%hash #the \ tells perl to store a reference # then you can use the reference like you would the hash by DEreferenc +ing it print "$reference->{one}"; # prints this
so in your case you would actually do sometihng like:
push @kung, \%item; print "Kungfoo is ->", $kung[0]{foo}, "<-\n";
Originally posted as a Categorized Answer.
|
---|
In Section
Seekers of Perl Wisdom