in reply to Defined vs. undefined

You're actually not checking to see if %hash is defined, but only if that specific element of the hash is defined. This is clearly not the same thing.

Now, as the prior respondents (all of whom have more Perl-dharma than do I) have noted, there are other ways of seeing if the hash is defined.

One is the obvious if(%hash), as in:

print "\%hash is defined\n" if(%hash);

or

you could try something like

$defined = keys(%hash);

My preference is for the first; it looks like it involves less work for Perl. The second looks like it's extracting all the keys so it can count them, and then throws away everything except the count. This seems wasteful.

emc

" When in doubt, use brute force." — Ken Thompson