Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: return of hash-assigment in list context (the fix)

by LanX (Bishop)
on Jan 02, 2013 at 22:06 UTC ( #1011364=note: print w/replies, xml ) Need Help??

in reply to Re^2: return of hash-assigment in list context (bug?)
in thread return of hash-assigment in list context (bug?)

Thx, this one looks good! =)

2010-09-11 David Mitchell
list cxt hash assign with dups gives garbage

the others are too new.

Fix for #31865: weird results from reverse( %x = reverse %h )

Basically, anything of the form

@a = %h = (list with some duplicate keys)

may have left @a containing weird and/or freed values.

There was a partial fix for this with ca65944e, but it was broken (it did one big block move on the stack at the end to remove duplicates, but duplicates weren't necessarily all in one block.)

The new fix is a two-stage process. First, while pulling key/value pairs of the stack and assigning them to the hash, each key/val pair is written back to the stack - possibly at a lower position if there are duplicates to be skipped.

Finally at the end if any duplicates have been detected, then in list context, a single pass is made through the stack, and for each key/val pair, the key is looked up and the val on the stack is overwritten with the new value (replacing possibly freed or other garbage values).

Cheers Rolf

  • Comment on Re^3: return of hash-assigment in list context (the fix)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011364]
[shmem]: me sinks back into the armchair by the fire, smikes a pope and calls this a day.
[shmem]: just one proverb before dozing off: when dealing with a bear, hubris is suicidal
[shmem]: Old_Gray_Bear would nod, and go back to sleep, then - but he's been sleeping for a year now.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2018-03-19 20:43 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.