in reply to Re: Delete a zero-valued hash element
in thread Delete a zero-valued hash element
...or you can do some reference judo:
You can clean up a lot of the ugly with:
print "oops" unless () = delete $hash{$key};Here's proof:
use YAML; use Test::More tests => 3; my %hash = map { $_ => $_ } 0 .. 3; for my $key (0 .. 1) { pass( "deleted $key" ) if () = delete $hash{$key}; } is( keys %hash, 2, "deleted two keys" ) or warn Dump \%hash;
|
|---|