|Perl: the Markov chain saw|
Re: List::Util - Bug in first? (odds)by tye (Cardinal)
|on Feb 18, 2008 at 16:12 UTC||Need Help??|
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.
to just throw out a few examples.