in reply to Re^2: Making Data::Dumper also displaying (stringified) Ref-ID's?
in thread Making Data::Dumper also displaying (stringified) Ref-ID's?
use Storable qw( dclone ); use Data::Dumper qw( Dumper ); my %hash = (a=>{b=>{c=>1}}); my %shallow = %hash; my %deep = %{ dclone(\%hash) }; local $Data::Dumper::Indent = 1; print("Shallow\n"); print("-------\n"); print(Dumper(\%hash, \%shallow)); print("\n\n"); print("Deep\n"); print("----\n"); print(Dumper(\%hash, \%deep));
Shallow ------- $VAR1 = { 'a' => { 'b' => { 'c' => 1 } } }; $VAR2 = { 'a' => $VAR1->{'a'} }; Deep ---- $VAR1 = { 'a' => { 'b' => { 'c' => 1 } } }; $VAR2 = { 'a' => { 'b' => { 'c' => 1 } } };
As you can see, the shallow copy clearly references back to the original, whereas the deep copy doesn't.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Making Data::Dumper also displaying (stringified) Ref-ID's?
by LanX (Saint) on Sep 27, 2009 at 21:08 UTC | |
by ikegami (Patriarch) on Sep 27, 2009 at 21:48 UTC |