Often I will test some base-level part of a Perl routine I am writing,
even if it is something I already know, just to make sure it really
works as expected. I find that this makes later debugging easier.
Anyway, I need to count how many 'records' I have in a hash after my
program gets done stuffing values into it. So I wrote a piece of test
code that goes like this:
------------------------
use warnings;
%parts = {};
$parts{'ms51957-101'} = 1207;
$parts{'ms51957-102'} = 17;
$parts{'ms51957-103'} = 1;
print "Number of Records in hash: ", scalar keys %parts, "\n";
Number of Records in hash: 4
------------------------
To my surprise, this is wrong; there are only 3 records in the hash.
NOW for the weird part. On a hunch, I changed the line:
%parts = {};
...to...
%parts = ();
Now I get:
Number of Records in hash: 3
...which is correct. Anyone out there know what gives?? And which is the
"correct" way to define an empty hash, {} or ()?
Barry Brevik
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs