Thanx toolic, indeed I have to read this thoroughly.
I was actually looking for a way to display the difference between deep and flat copy to a newbie, and no figured out that the Seen-Mechanism in Data::Dumper already reveals it, without the need to print the Ref-IDs. 8)
DB<90> $hr2={%$hr1} # shallow copy
DB<91> print Data::Dumper->Dump([$hr1,$hr2],[qw/hr1 hr2/])
$hr1 = {
'a' => {
'b' => {
'c' => 1
}
}
};
$hr2 = {
'a' => $hr1->{'a'}
};
DB<92> x $hr1,$hr2
0 HASH(0x8b64b78)
'a' => HASH(0x8b64c18)
'b' => HASH(0x8af9120)
'c' => 1
1 HASH(0x8b156c0)
'a' => HASH(0x8b64c18)
-> REUSED_ADDRESS
Anyway IMHO an option to add the IDs as comments would be welcomed by many people as a valuable feature!
(update: maybe this can be done with Data::Dump::Streamer?)
UDPATE: improved code example |