#!/usr/bin/perl -w use strict; use Data::Dump qw(pp); use Data::Dumper; my %HoH = ( flintstones => { lead => "fred", pal => "barney", }, jetsons => { lead => "george", wife => "jane", "his boy" => "elroy", }, ); my $href1 = \%{$HoH{flintstones}}; my $href2 = $HoH{flintstones}; my $href3 = \%HoH; #Fails #yes, indeed this will fail!! #delete($href1); #delete($href2); # These are both references to the sub hash of flintstones... # sometimes the ability to omit parens in Perl is good thing # sometime not, here not: print pp ($href1), "\n"; #{ lead => "fred", pal => "barney" } print pp ($href2), "\n"; #{ lead => "fred", pal => "barney" } print "printing HOH...\n"; print pp ($href3), "\n"; #printing HOH... #{ # flintstones => { lead => "fred", pal => "barney" }, # jetsons => { "his boy" => "elroy", lead => "george", wife => "jane" }, #} foreach my $TV_show (keys %HoH) { delete $HoH{$TV_show} if $HoH{$TV_show} == $href1; } print "printing HOH after the delete... flintstones are gone...\n"; print pp ($href3), "\n"; #printing HOH after the delete... flintstones are gone... #{ # jetsons => { "his boy" => "elroy", lead => "george", wife => "jane" }, #} #### change: delete $HoH{$TV_show} if $HoH{$TV_show} == $href1; to: $HoH{$TV_show}={} if $HoH{$TV_show} == $href1;