Here is some code for you...
I like pp in Data::Dump although it is not a core module, it is nice for compact representations of structures.

In order to delete the keys associated with $href1 or $href2 (they are the same), it is necessary to cycle through the keys of %HoH, and compare $href1 against the values of those keys...

#!/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" + }, #}
Update: it occurred to me, that perhaps you may want "flintstones" to point to an empty hash. in that case:
change: delete $HoH{$TV_show} if $HoH{$TV_show} == $href1; to: $HoH{$TV_show}={} if $HoH{$TV_show} == $href1;
$HoH{$TV_show}={} means: allocate new hash memory and assign a reference to it to $HoH{$TV_show}

In reply to Re: Deleting from Hash-of-Hash using references by Marshall
in thread Deleting from Hash-of-Hash using references by dol

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.