Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Re: Scalars, Lists, and Arrays

by merlyn (Sage)
on Apr 13, 2001 at 17:37 UTC ( #72335=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Scalars, Lists, and Arrays
in thread Scalars, Lists, and Arrays

I've also found it important to thump the desk when I'm teaching about this topic, over two very specific things:

  1. A list never gets produced in a scalar context.
  2. What a construct does produce in a scalar context must be learned, not derived by any general rule.
So, if you learn about what @foo does in a scalar context, that tells you nothing about what @foo[3..5] does in a scalar context, or even what ($x,$y,$z) does in a scalar context. You must learn them each individually.

As it turns out, there is a bit of consistency in it (it's not just random madness), but that's available only after the fact. {grin}

-- Randal L. Schwartz, Perl hacker


Comment on Re: Re: Re: Scalars, Lists, and Arrays
Select or Download Code
Replies are listed 'Best First'.
(tye)Re2: Scalars, Lists, and Arrays
by tye (Cardinal) on Apr 13, 2001 at 18:25 UTC

    I'll agree with your "A list never gets produced in a scalar context", but only for certain values of "never", "list", and/or "produced". :) That is an important concept that needs to be stressed (though I'd put less stress on the "never" part myself).

    But, for the curious, see the last half of (tye)Re: Hash slices ? for a specific example of what I consider to be a list of SVs being (temporarilly) produced despite a scalar context. I'm not trying to contradict the above rule. I am trying to prevent it from being "over interpretted", but more than that, I think the example will help some people understand the concept better.

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2015-07-29 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls