Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

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

If you try to memorize a big list of cases (whether you pejoratively label them "special" doesn't matter), then you are doing it wrong. This is the same mistake many people make with the precedence table.

Instead, understand why the cases are there and they are easy to remember. For both scalar context and operator precedence, there are a minority of exceptions that have little sense behind them (and most of those have both a reason why they "don't matter as much" and historic context that explains the imperfect design). The majority are well justified and thus easy to understand and remember.

If it isn't clear what the useful scalar value is for a particular operation, then reasonable responses include 1) looking up what the scalar return is in that case and why, 2) wondering why you are using scalar context in a way that doesn't make clear sense.

A really bad response is: consult a fundamentally flawed "model" to make a guess at what is returned and then either be surprised or pat yourself on the back and still not have any clue why that is the most useful thing to return (or, less often, why there isn't really an obvious answer and something more arbitrary got implemented or, rarest, why something other than the most useful value got implemented).

Yes, part of a correct model here is "it depends". Inventing an incorrect model, especially one as elaborate as "is it an array or is it a list?" tends to become, just so you can use it to make poorly-motivated guesses and avoid understanding how scalar context is useful in many cases, seems of dubious value at best. Certainly not enough value to justify the wrong answers it provides much less the confusion it leads to.

It's useful to have some default model to explain common behaviour.

A slice in scalar context is "common behavior"? I don't think so.

- tye        

In reply to Re^5: Confused as to why the "casting context" is mis-behaving (cases) by tye
in thread Confused as to why the "casting context" is mis-behaving by kiz

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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2018-02-18 00:23 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (250 votes). Check out past polls.