Have a look at the delete documentation. One big thing to notice is that it does not set $! if there's an error, so there's no point in reporting it.
If you really want to test how many things were deleted, you can assign to an array like this:
my @deleted = delete $hash{$key}; (1 == scalar @deleted) || print "oops";
...or you can do some reference judo:
(1 == scalar @{[delete $hash{$key}]}) || print "oops";
Note however, this doesn't actually tell you how many were deleted but rather how many you asked to be deleted. Each item that you tried to delete that was already gone will be undef in the resulting list. You could say something like this:
scalar grep { defined } delete $hash{$key};
...but this will be wrong in the case where one of the things deleted actually was the undef value.
Basically, I don't think you can check delete for errors.
In reply to Re: Delete a zero-valued hash element
by kyle
in thread Delete a zero-valued hash element
by sush
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |