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

Comment on

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

The proposed rule was:

When a LIST is evaluated in scalar context every element of the list is evaluated in scalar context and the value of the last element is the value of the LIST, with all the other values being discarded.

I said that doesn't account for precedence. Here's a very simple example:

my $x = 1, 2, 3;

Many people might say that 1, 2, 3 is a list, and it's obvious that my $x = supplies scalar context. The problem (at least for the proposed rule) is that = has a higher precedence than ,, so Perl's parser turns this code into three expressions:

my $x = 1, 2, 3;

Because the second and third expressions have no side effects (they're just constants) and they're in void context (use warnings to see that), they get optimized away. That's why they're not present if you use B::Deparse to see what Perl sees.

(Besides that, this proves that the general rule "A list in scalar context evaluates to its final element" is wrong, too.)

How about another example?

my @y = 1 .. 8; my $x = @y, 2, 3; print $x;

That's why I say the proposed rule has big problems. What looks like a list to a casual reader is often not the list that Perl sees -- and all of the talk about evaluating elements in scalar context and evaluating to the final element of the list is wrong.

In reply to Re^4: If you believe in Lists in Scalar Context, Clap your Hands by chromatic
in thread If you believe in Lists in Scalar Context, Clap your Hands by gone2015

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and dust plays in a shaft of sunlight...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (10)
    As of 2018-06-22 18:00 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (124 votes). Check out past polls.