SPUG: Slice of HashOfHash
Colin Meyer
cmeyer at helvella.org
Wed Nov 15 18:47:56 PST 2006
On Wed, Nov 15, 2006 at 04:39:23PM -0800, Juan Jose Natera wrote:
> On the other hand, if you do need to keep a copy of the results:
>
> my %matched = map { $_ => $HoH{$_} } grep { $HoH{$_}->{husband} eq
> 'fred' } keys %HoH;
It is worth noting that the "copy" contains the same references as the
original, so that any modifications to the subhashes in the copy also
show up in the original. If you need a deep copy, try a slight
modification:
use Storable 'dclone';
my %matched = map { $_ => dclone( $HoH{$_} ) }
grep { $HoH{$_}->{husband} eq 'fred' } keys %HoH;
-Colin.
More information about the spug-list
mailing list