muntfish has asked for the wisdom of the Perl Monks concerning the following question:
I've just discovered some odd behaviour in some code written for perl 5.004_xxx but now running under 5.8.0. A hash is being initialised like this:
%rec_counts={};
and later on, updated like this:
while (defined($line = <F>)) { $rec_type = substr($line, 19, 2); $rec_counts{$rec_type} += 1; }
And finally we print out the record types using:
foreach $key (sort keys(%rec_counts)) { print "Record count of $key is $rec_counts{$key}\n"; }
This gives me the output:
Record count of 00 is 1 Record count of HASH(0x4000473c) is Record count of T is 315
Now, under perl 5.004_x it does not print the middle line, I just get the "real" record types 00 and T. I've narrowed this down to the "initialisation" which behaves correctly if I change it to %rec_counts=(). So I guess I have two questions:
What exactly changed between 5.004 and 5.8.0?
What is the {} syntax doing exactly in 5.8.0? The docs suggest it is creating an empty hash but maybe I'm reading it wrong...
Any insight into this would be most appreciated, thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Construction/initialisation of empty hash
by broquaint (Abbot) on Apr 27, 2004 at 14:39 UTC | |
by muntfish (Chaplain) on Apr 27, 2004 at 14:52 UTC | |
by Anomynous Monk (Scribe) on Apr 27, 2004 at 17:17 UTC | |
|
Re: Construction/initialisation of empty hash
by dragonchild (Archbishop) on Apr 27, 2004 at 14:32 UTC | |
by muntfish (Chaplain) on Apr 27, 2004 at 14:41 UTC | |
by dragonchild (Archbishop) on Apr 27, 2004 at 14:48 UTC | |
|
Re: Construction/initialisation of empty hash
by hv (Prior) on Apr 27, 2004 at 17:37 UTC | |
by muntfish (Chaplain) on Apr 27, 2004 at 18:38 UTC |