Hello all!
Caveat: I'm fairly new to Perl so the answer may be obvious.
I'm trying to delete a key in a hash-of-hashes using references. I wrote some mock-up code isolating the issue:
#!/usr/bin/perl -w use strict; 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; print "\$HoH{flintstones}: $HoH{flintstones}\n\$href1: $href1\n\$href2 +: $href2\n\$href3->{flintstones}: ",$href3->{flintstones},"\n"; #Works delete($HoH{flintstones}); #delete($href3->{flintstones}); #Fails #delete($href1); #delete($href2);
Output:
$ ./hashreftest2.pl $HoH{flintstones}: HASH(0x7ce220) $href1: HASH(0x7ce220) $href2: HASH(0x7ce220) $href3->{flintstones}: HASH(0x7ce220)
From the output all four variables look equivalent to me. But any of the last two commented delete lines (i.e. "delete($href1);" and "delete($href2);") fails with this error:
delete argument is not a HASH or ARRAY element or slice at ./hashreftest2.pl line 29.I have searched the web but still can't understand why this happens. Any help is appreciated. In case it matters I'm running Perl v5.12.3 under Linux.
Thank you!
In reply to Deleting from Hash-of-Hash using references by dol
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |