in reply to On Scalar Context
This just came up again on use Perl . I see four large factions here:
Things that take a list and return a list in list context and return a count of items in scalar context. The sole notable exception is sort.
Things that take a scalar and return a list in list context tend to return a scalar in scalar context, and you can call them with the same input scalar to get the next element of what would have been a list in list context.
Literal list operators
Things that construct a list and give it to you in list context but only its last element in scalar context.
“I’m chatty in list context”
Things that can provide a bunch of information, which you get all of in list context, and the first first bit of in scalar context.
The rest is a tiny inconsistent minority.
The hash-related functions kind of belong to the list functions and kind of to the iterators – particularly the oddball each, which is the only thing that functions as an iterator in both contexts. But that is because hashes are kind of oddball anyway in terms of context.
So the return values are consistent, their consistency is just inconsistent.
Makeshifts last the longest.