The problem is not about what happens, which is eminently described by your rules.

The problem is how to discuss what happens and why, without complex ascii-art diagrams, or multiply subscripted essays, for the two common results of symbolic (source code) expressions that appear (conceptually) to produce multiple values, when those constructs occur (directly or indirectly) in a scalar context. Namely:

  1. They result in a scalar that is the number of those multiple values that would have been produce had that same construct appeared in a list context.
    @a = 'a'..'d';; print @a;; a b c d print scalar @a;; 4
  2. They result in a scalar that is 'last' value of the multiple scalars that would have been produced had the same expression appeared in a list context.
    print('a'..'d');; a b c d print scalar ('a','b','c','d');; d

In the context of the original thread, the question was asked: Why does a slice @a[0..$#a] produce a different result in a scalar context to the array, when they both produce identical results in a list context. (Or meaning to that effect.)

And the reply (with licence), that started this discussion, was: Because a slice acts like a list in a scalar context.

The problem that arises is that people, (those in the know), will insist on taking that use of the word 'list' to mean some ethereal, maybe-exists or maybe-doesn't, internal state; rather than the more general, more useful, concrete concept of what has (in at least one post) been alternatively named a 'list constant'.

So, in order to be able to discuss and relate to discussion, and to be able to categorise the effects of the many constructs in a scalar context, the following two phrases might be used to relate any given expression to the well known and broadly understood situations in 1 & 2 above:

  1. The result of expression X in a scalar context, will be a count of the items in the list produced where that same expression appears in a list context. Similar in effect, to when an array expression appears in a scalar context.
  2. The result of expression X in a scalar context, will be the last item from the list that would have been produced where that same expression appears in a list context. Similar in effect, to when a list (constant) appears in a scalar context.

And those two wordy (and I hope inarguably accurate:), phrases should be replacable by:

  1. In a scalar context, expression X acts similarly to an array expression.
  2. In a scalar context, expression X acts similarly to a list (constant).

In turn, if people would accept that in the context[sic] of posts like the one that started this saga, that the term 'list' is most likely to mean the concrete variety, rather than the nebulous, ethereal source divers-only meaning, then the phrase "It acts like a list in a scalar context", is a simple, convenient and conceptually accurate way of describing what happens when (for example), an array slice expression appears in a scalar context.

For me, the crux of this whole saga is that attempt by certain somebodies to infer a meaning from the use of the term 'list' that simple doesn't appear on the horizons of most SoPWs; nor even the greater majority of Perlers. And then jump on people because of that (wrong) inference.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

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

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!
  • 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, details, 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, summary, 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.