No. When you take a reference to a hash (or anything else) with \ you are not making a copy. Dereferencing the reference accesses the original.
Consider the following:
use strict; use warnings; my %hash = ( foo => 1, bar => 2, baz => 3 ); my $rhash1 = \%hash; my $rhash2 = { %hash }; $rhash1->{ baz } = 5; $rhash2->{ bar } = 7; use Dumpvalue; my $dumper = Dumpvalue->new(); print "\%hash:$/"; print $dumper->dumpValue( \%hash ); print "\$rhash1:$/"; print $dumper->dumpValue( $rhash1 ); print "\$rhash2:$/"; print $dumper->dumpValue( $rhash2 ); __END__ %hash: 'bar' => 2 'baz' => 5 'foo' => 1 $rhash1: 'bar' => 2 'baz' => 5 'foo' => 1 $rhash2: 'bar' => 7 'baz' => 3 'foo' => 1
Update: s/dumpvalue/dumpValue/. Thanks ww.
the lowliest monk
In reply to Re: references changing a hash value
by tlm
in thread references changing a hash value
by tcf03
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |