LanX has asked for the wisdom of the Perl Monks concerning the following question:
(EDIT: for a simplified bug-demo see update further down and one-liner post)
For Re: Syntax explanation required I tried to show the elimination of duplicates when assigning a list of two hashes to a third hash.
But while the third hash holds the correct results (line 105) the return value (line 102) of the assignment looks very weird, and I can't really explain whats happening.
DB<100> %h1=(a=>1,b=>2); => ("a", 1, "b", 2) DB<101> %h2=(a=>11,c=>3); => ("a", 11, "c", 3) DB<102> %h=(%h1,%h2) => ("b", 2, "b", 2, "c", 3) DB<103> @ret = ( %h=(%h1,%h2) ) => ("b", 2, "b", 2, "c", 3) DB<104> \@ret => ["b", 2, "b", 2, "c", 3] DB<105> %h => ("c", 3, "a", 11, "b", 2)
to be sure that it's not just my repl showing buggy results I reproduced it again on the console:
> perl %h1=(a=>1,b=>2); %h2=(a=>11,c=>3); print (%h3=(%h1,%h2),"\n"); print %h3; __END__ b2b2c3 c3a11b2
I'm still suffering from a little hangover from recent tumultuous events ... ;-)
So please could someone tell me what I am missing here?
Cheers Rolf
UPDATE:
I was able to further isolate whats happening to a simple list assignment:
DB<107> %h=("a", 1, "b", 2, "c", 3, "a", 11) => ("b", 2, "b", 2, "c", 3) DB<108> %h=("a", 1, "b", 2, "c", 3, "d", 4) => ("a", 1, "b", 2, "c", 3, "d", 4) DB<110> %h=("a", 1, "a", 11, "b", 2) => ("a", 11, "a", 11)
seems like that the fact that duplicated keys are eliminated (here a) somehow confuses the returned value.
|
|---|