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

Re: On Scalar Context

by Aristotle (Chancellor)
on Oct 02, 2005 at 06:15 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found