in reply to One liner to Check and undef hash elements
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: hash problem
by Anonymous Monk on Apr 16, 2003 at 00:53 UTC |