Hey folks!
I discovered the hard way (is there ever an easy way???) that declaring
constants and then using these as hash keys does not achieve the expected
(by me, just by me!) results. Rather that using the constant _value_ as the
hash key, it uses the constant _name_!
Arrays behave as expected (by me.) though.
Is that a bug or a feature? Why isn't it consistent: use either the
constants name in both arrays and hashes or their value, right?
Here is a small script to demonstrate the claim. Does your result vary?
use strict;
use constant FIRST => "1'st";
use constant SECOND => "2'nd";
use constant THIRD => "3'rd";
my %hash = (
FIRST => 'one',
SECOND => 'two',
THIRD => 'three',
);
my @array = (FIRST , SECOND, THIRD);
foreach my $key (sort keys %hash) {
print "Hash key: $key, Hash value: $hash{$key}\n";
}
print "Array contents: ", join (", ", @array), "\n";
# produces:
# Hash key: FIRST, Hash value: one
# Hash key: SECOND, Hash value: two
# Hash key: THIRD, Hash value: three
# Array contents: 1'st, 2'nd, 3'rd
Regards,
Meir
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl