...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;
In reply to Re^2: Delete a zero-valued hash element
by chromatic
in thread Delete a zero-valued hash element
by sush
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |