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?

Dump the original and the copy using one call to Dumper, and the difference between a shallow and a deep copy will be obvious.
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
    Thx, but what's the difference to the code in the post you're replying to?

    IMHO it's essentially the same code!(?)

    Cheers Rolf

      I didn't notice the call to Data::Dumper. I thought the dump was actually initialisation for the subsequently demonstrated debugger solution.