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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

First, some corrections:

$r = 'a'..'z' ; # Case 4 -- error

Maybe, but $r = 5..7; wouldn't be.

$r = (@r, @r) ; $v = (%r, %r) ;

the @r and %r are evaluated in Scalar Context

No, they're not.

use strict; use warnings; sub print_context { my $c = ( wantarray() ? 'List' : ( defined(wantarray()) ? 'Scalar' : 'Void' ) ); print("$c\n"); } my $r1 = ( print_context(), print_context() ); # Void # Scalar

However, they would be evaluated in scalar context in the following similar code:

my $r2 = sub { ( print_context(), print_context() ) }->(); # Scalar # Scalar

Now, some questions for you:

in List Context there are a number of things which make lists, including:

  • the empty list
  • singleton values (including undef)
  • literal lists -- two or more values separated by ',', grouped together by '()' if required
  • the '..' range operator
  • slicing other lists, arrays or hashes

How come array slices and hash slices are in that list, but not arrays and hashes?

Why aren't any named operators (such as grep and map) in that list?

what's wrong with the notion of a List in Scalar Context ?

Given that an array returns a list in list context, how do you place that list in scalar context?


Finally, an answer to your question:

BTW: I'm gagging to know how to describe why this:

$r = () = 1..27 ;

A list assignment ("() = 1..27") in scalar context ("$r =") evaluates to the number of elements to assign.

Finally, and for extra points (and points mean prizes), how does one describe the difference between a list and an array ?

An array is variable.
A list is a piece of code that generates a list operator.
A list is the operator generated from a list in the code.
A list is the result of an operator or function in list context.


In reply to Re: If you believe in Lists in Scalar Context, Clap your Hands by ikegami
in thread If you believe in Lists in Scalar Context, Clap your Hands by oshalla

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (19)
    As of 2014-07-24 19:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (165 votes), past polls