mscharrer has asked for the wisdom of the Perl Monks concerning the following question:
Now my actual question: Is this a defined, stable thing, e.g. always the last key in the array would win? Or is it - for any reason - the first? Is it not explicitly defined and depends on something like the internal hash structure, e.g. the exact key names?my @array = ( 'A', 1, 'B', 2, 'C', 3, 'A', 4 ); my %hash = @array; # $hash{A} == 4 or 1 or depends??
I came to this question when I had code where I have to add certain key/value pairs to an existing hash and want to make sure that already existing keys are overwritten:
of course I could just take a loop for this but I like the simplicity of this line and because the existing hash isn't very big the reassigning to itself is not very expensive. Now I would like to know if this really works like I think it does.%hash = (%hash,@array); # or %hash = (%hash,%otherhash);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assigning list with duplicate keys to hash
by Fletch (Bishop) on Apr 22, 2008 at 16:04 UTC | |
by mscharrer (Hermit) on Apr 22, 2008 at 17:01 UTC | |
|
Re: Assigning list with duplicate keys to hash
by kyle (Abbot) on Apr 22, 2008 at 15:04 UTC | |
by Your Mother (Archbishop) on Apr 22, 2008 at 17:23 UTC | |
|
Re: Assigning list with duplicate keys to hash
by apl (Monsignor) on Apr 22, 2008 at 15:08 UTC | |
|
Re: Assigning list with duplicate keys to hash
by dwm042 (Priest) on Apr 22, 2008 at 14:52 UTC | |
by mscharrer (Hermit) on Apr 22, 2008 at 15:06 UTC | |
by bgs (Initiate) on Aug 03, 2010 at 06:37 UTC | |
by toolic (Bishop) on Aug 03, 2010 at 13:12 UTC |