Note, too, that the exact operator precedance in Perl5 is poorly defined, and there are many edge cases that don't work out quite as you'd expect.
Gah, you make it sound as though Perl rolls dice to determine operator precedence. The exact operator precedence in Perl is quite well-defined, and there are no random number generators involved. But people fail to understand it in two different ways. First, they simply don't bother to learn the precedence table, which was the problem in this case (and is the usual problem). I think people get lazy because operator precedence usually DWIMs, so they figure it will always DWIM, and then are surprised when it doesn't.

The other way that people fail to understand operator precedence is that they don't know when it doesn't apply. It's important to understand that a yacc grammar uses operator precedence only to break ties between ambiguous rules in the grammar. If the grammar specifies that something can only be parsed in a particular way, operator precedence never comes into it. You may think that the $ on the front of a variable is a unary operator, but it's not, because what comes after it is not allowed to be a general expression. The grammar restricts the following item to be an identifier, a simple scalar variable, or a block, and these are all recognized by the grammar without recourse to operator precedence. If you try to treat $ as a unary operator, you will certainly be surprised when it doesn't work that way. But it's not an "edge case" of operator precedence. It's simply getting nowhere near the operator precedence table in the first place.


In reply to Re: Re: Short Circuit Operator and Hash Assignment by TimToady
in thread Short Circuit Operator and Hash Assignment by periapt

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.