in reply to Re: Massive Perl Memory Leak
in thread Massive Perl Memory Leak

Do any of u see any problem with my hash usage? Specifcally:

 %{$datahash{"devinfo"}} = %devinfo; I'm curious as to how the deep nature of %devinfo is copied over to the %datahash branch. As in do any refs to the original var survive? Or is that a 100% clean copy with no strings attached.

Would either of these be equivalent or better syntax? :

$datahash{"devinfo"} = \%devinfo; $datahash{"devinfo"} = %devinfo; # this must be wrong

Replies are listed 'Best First'.
Re^3: Massive Perl Memory Leak
by GrandFather (Saint) on Jun 11, 2007 at 21:15 UTC

    Consider:

    use strict; use warnings; use Data::Dump::Streamer; my %devinfo = (1 => {a => 'apple', b => 'orange'}); my %datahash = (devinfo => {}); %{$datahash{"devinfo"}} = %devinfo; Dump (\%devinfo, \%datahash, $datahash{devinfo});

    Prints:

    $HASH1 = { 1 => { a => 'apple', b => 'orange' } }; $HASH2 = { devinfo => 'A: $HASH3' }; $HASH3 = { 1 => $HASH1->{1} }; alias_hv(%$HASH2, 'devinfo', $HASH3);

    The copy is a shallow copy. If any of the values of %devinfo are references then the copy simply duplicates the reference. You may find Storable's dclone helps if you are looking for a clone of the data.


    DWIM is Perl's answer to Gödel