Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: If you believe in Lists in Scalar Context, Clap your Hands

by jwkrahn (Monsignor)
on Oct 25, 2008 at 02:15 UTC ( #719464=note: print w/ replies, xml ) Need Help??


in reply to Re^3: If you believe in Lists in Scalar Context, Clap your Hands
in thread If you believe in Lists in Scalar Context, Clap your Hands

chomp???   How did chomp get in there?   It never returns a list.


Comment on Re^4: If you believe in Lists in Scalar Context, Clap your Hands
Download Code
Re^5: If you believe in Lists in Scalar Context, Clap your Hands
by massa (Hermit) on Oct 25, 2008 at 02:59 UTC
    when used with a list, it returns the total number of characters chomped... and not a list (so, you are right that there is no "list context" to it.
    []s, HTH, Massa (κς,πμ,πλ)
Re^5: If you believe in Lists in Scalar Context, Clap your Hands
by chromatic (Archbishop) on Oct 25, 2008 at 10:21 UTC
    my @x = chomp <DATA>;

    Bingo, @x is gets a one-element list -- or at least, it's a list in list context and a scalar in scalar context. Tricky! Here's a mind-bender. What's this?

    1, 2, 3

    It could be a three-element list, in list context, or it could be a scalar and two void expressions (which get optimized away), in scalar context. In void context, it could be nothing.

    Update: Reworded one sentence.

      So, then, scalar also returns a list in list context?   (BTW, @x is an array, not a one element list.)

        So, then, [scalar[ also returns a list in list context?

        Yes, a one-element list.

        (BTW, @x is an array, not a one element list.)

        You're right. I misworded that sentence and have corrected it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-09-02 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (32 votes), past polls