in reply to Re: hash problem
in thread One liner to Check and undef hash elements

Hi crenz, thanks for you reply. #2 works very nicely, but I can't make #1 work. Your code prints "empty" for both of these hashes.
$hash->{'a'} = 1; $hash->{'b'} = undef; $hash->{'c'} = undef; $hash->{'d'} = undef; if (scalar grep {defined} values %{$hash} == 0) { print "empty\n"; } $hash->{'a'} = undef; $hash->{'b'} = undef; $hash->{'c'} = undef; $hash->{'d'} = undef; if (scalar grep {defined} values %{$hash} == 0) { print "empty\n"; }