Re: packing an array of hashes

[email protected] ("Mr. Shawn H. Corey")
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
Chris Cosner wrote:
> If you put a hash reference into an array
>     push @array, \%hash;
> you do not store any actual hash data in the array.
> So if you change the hash, then later pull the hash reference from the 
> array and access it, you get changed data.

push @array, { %hash };

This creates an anonymous hash and populates it with the contents of %hash.  It makes a copy of %hash.  Of course, if %hash has any references, they will be copied but not their contents.


-- 
Just my 0.00000002 million dollars worth,
  Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.