Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: List::Util - Bug in first? (odds)

by tye (Sage)
on Feb 18, 2008 at 16:12 UTC ( #668588=note: print w/replies, xml ) Need Help??

in reply to List::Util - Bug in first?

to prevent getting a (true!) list with one value (of undef), which in scalar context is true

You can't get a list in a scalar context so your terminology is quite sloppy (but typical of those following this mantra of Perl Best Practices).

Does your example code look like something that you would expect somebody to write and then be surprised at the results?

In my experience, it is very unlikely for somebody to assign the results of a single function that always returns just one scalar to an array and then test the array (or the assignment) for "truth".

If you make the suggested change, then you create the potential for a whole slew of "bugs" that together seem more plausible than the problem you "fix". Any place you might use first() in a list context now becomes "either a scalar or the empty list". It certainly makes for a serious problem in backward compatibility to change it now. Though, some unfortunate complexities of Perl prototypes actually make it quite awkward to use first() as part of a list, which reduces the likelihood of these types of problems in this case.

push @results, first ...; @hash{ @list }= map { first {test($_)} candidates($_) } @list; use warnings; foo( { -option => first ... } );

to just throw out a few examples.

- tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://668588]
[marto]: Re: Monastery login over http
[Corion]: Veltro: This is due to the fact that one of our webservers doesn't have "our" https certificate but another https certificate. Work is underway (well, on my long, long to-do list) to switch even that server over to "our" certificate

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2018-05-23 11:22 GMT
Find Nodes?
    Voting Booth?