Do you know where your variables are? | |
PerlMonks |
Test Presence of Data in Hashby bichonfrise74 (Vicar) |
on Jul 20, 2009 at 20:36 UTC ( [id://781758]=perlquestion: print w/replies, xml ) | Need Help?? |
bichonfrise74 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I wanted to test if there are any data in a hash. So, I was thinking of simply using something like this... If I run this, 'test_1' is not printed which means there are no data in the hash. This is what I want. But for some reason, 'test_2' is printed. Since I initialized the hash, shouldn't it be undefined already? I'm just curious why it printed. I checked the documentation and it did mention that using something like defined( %hash ) is already deprecated and I should just use ( %hash ) to test for the presence of the data in the hash. Now, if I try to make a small change to this code where I declare and initialize the hash at the same time... Then, nothing will be printed at all. Didn't I initialized the hash in both cases? Any ideas on this?
Back to
Seekers of Perl Wisdom
|
|