Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: On Scalar Context

by Aristotle (Chancellor)
on Oct 02, 2005 at 06:15 UTC ( #496726=note: print w/replies, xml ) Need Help??

in reply to On Scalar Context

This just came up again on use Perl (and again). I see four large factions here:

  1. List functions

    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.

  2. Iterators

    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.

  3. Literal list operators

    Things that construct a list and give it to you in list context but only its last element in scalar context.

  4. “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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2020-02-26 14:35 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (117 votes). Check out past polls.