in reply to How to have a subroutine return an undefined hash

my %hash = getHash(); if (! defined(%hash)) { print "undef\n"; } else { print "not undef\n"; }

Replies are listed 'Best First'.
Re^2: How to have a subroutine return an undefined hash
by Fletch (Bishop) on Apr 26, 2005 at 12:53 UTC

    Quoth perldoc -f defined:

    Use of "defined" on aggregates (hashes and arrays) is depre- cated. It used to report whether memory for that aggregate has ever been allocated. This behavior may disappear in future versions of Perl. You should instead use a simple test for size: if (@an_array) { print "has array elements\n" } if (%a_hash) { print "has hash members\n" }
      Gawd! Moving targets, yet. Thank you, Fletch, I stand corrected!