in reply to Assigning list with duplicate keys to hash

I don't claim to know anything about the guts of Perl, but in an assignment from an array to a hash, how the hash stores key value pairs should be immaterial. What is material is how Perl scans the array for elements and whether those elements are stored in the array in deterministic ashion. As far as I can tell, they are.

Testing, I get:

#!/usr/bin/perl use warnings; use strict; my @array = ( 'A', 1, 'B', 2, 'C', 3, 'A', 4 ); my %hash = @array; for (sort keys %hash ) { print "$_ => $hash{$_}\n"; } print "\n";
And the output is (for Active State Perl 5.8.8):

C:\Code>perl array-hash-order.pl A => 4 B => 2 C => 3

Replies are listed 'Best First'.
Re^2: Assigning list with duplicate keys to hash
by mscharrer (Hermit) on Apr 22, 2008 at 15:06 UTC
    What is material is how Perl scans the array for elements and whether those elements are stored in the array in deterministic ashion. As far as I can tell, they are.
    Yes, I came to the same conclusion. It makes sense that Perl is just reading the array elements and assigns the pairs to the hash. That would be deterministic. The thing is just to really be sure that this is always the case. Highly probably it is but I just wanted to seek the wisdom of other monks.
Re^2: Assigning list with duplicate keys to hash
by bgs (Initiate) on Aug 03, 2010 at 06:37 UTC
    Hi I have a same requirement to append the values of duplicate keys, like A => 1,4 in the above example. can anyone please help me?