Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I'm suprised nobody else told you yet with as many words: there's no such thing as a "list in scalar context".

    So you think map and grep do return a list in scalar context? They don't. They return, in true Perl tradition, a list in list context, and they return "some useful value" in scalar context, which needn't even be related to that list. As grep and map in list context do not necessarily return the same number of items as they have arguments, it makes sense to make them return the count of items they would have returned. For grep that makes it easy for us to count the number of matches, very useful indeed.

    But what's your excuse for sort? You could just as well expect it to behave as the comma operator, returning a list in list context (as usual), and the value of the last item of that list in scalar context. So sort in scalar context would then return the maximum value. Makes sense. ;-)