On 12-01-31 01:11 PM, Matt wrote:
When I copy a hash like so:

my %hash2 = %hash1;

Modifying hash2 seems to modify hash1.  How do I make it so there both
independent after being copied?


This creates a shallow copy. It does not copy the contents of any references in the hash. To do that, use dclone() from Storable.

  use Storable qw( dclone );
  %hash2 = %{ dclone( \%hash1 ) };

See `perldoc Storable` for details.


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

Strength is not a measure of the body.
It's a measure of the heart.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to