Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Strange behavior with List::Util qw{first} on perl >= 5.20

by Anonymous Monk
on May 26, 2015 at 21:41 UTC ( #1127901=note: print w/replies, xml ) Need Help??


in reply to Strange behavior with List::Util qw{first} on perl >= 5.20

Hmmmm... Perl v5.20:

$ perl -MList::Util=first -le 'print first {lc eq "abc"} keys %{{ABC=>"ABC"}}' abc $ perl -MList::Util=first -le 'print first {uc eq "ABC"} keys %{{ABC=>"ABC"}}' ABC $ perl -MList::Util=first -le 'print first {/abc/i} keys %{{ABC=>"ABC"}}' ABC $ perl -MList::Util=first -le 'print first {lc eq "abc"} values %{{ABC=>"ABC"}}' ABC $ perl -MList::Util=first -le 'print first {lc eq "abc"} "ABC"' ABC $ perl -MList::Util=first -le 'print first {lc eq "abc"} values @{["ABC"]}' ABC

On v5.10 they all (except for the last one) give "ABC". The inverse case, first {uc eq "ABC"} keys %{{abc=>"abc"}}, also gives the "unexpected" result "ABC". Smells like a bug... could this be rt://96343?

Replies are listed 'Best First'.
Re^2: Strange behavior with List::Util qw{first} on perl >= 5.20
by Anonymous Monk on May 26, 2015 at 23:09 UTC

    A git bisect appears to confirm that. The bug also still appears to be present in the latest v5.22.0-RC2.

      There's something fishy about $_. It's a TEMP with REFCNT=1. I believe that means it's a mortal. If so, that means noone claims a reference to $_, but first still uses it after the callback returns. This points to a bug in List::Util.

      That said, the inplace lc($_)[1] should probably only happen in void context.


      1. This is the first I've ever heard about this!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1127901]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-01-21 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (227 votes). Check out past polls.

    Notices?