in reply to Delete a zero-valued hash element
length delete ($hash{$key}) || print " There is some error : $! ";
update - Oops. A kyle states below, length doesn't work with zero length hash values. So, use
defined delete ($hash{$key}) || print " There is some error : $! ";
Ah.. well... I can see the next problem: what if you say $hash{$key} = undef? In that case defined(delete) will fail
perl -le '$h{""}=undef; print ">",defined delete $h{""},"<"' ><
since delete returns undef here. So, probably best advice is:
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Delete a zero-valued hash element
by kyle (Abbot) on Oct 02, 2007 at 20:05 UTC |