I'm sure somebody else will come up with something more optimal...
#1. if ((scalar grep {defined} values %{$hash}) == 0) { # all values are undef } #2. $hash = { map {$_ => undef} keys %{$hash} }; # now empty
Update: Changed > 0 to == 0, since the poster asked for "check if empty"
Update: Fixed precedence problem (pointed out by original poster). Works now.
In reply to Re: hash problem
by crenz
in thread One liner to Check and undef hash elements
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |