Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by tye (Cardinal)
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        


Comment on Re: List::Util - Bug in first? (odds)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://668588]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-10-01 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (29 votes), past polls