When I look at the operator precedence table, I notice that the '=' is two spots higher in the table

Precedence is irrelevant here. And local has higher precedence.

>perl -MO=Concise -e"local $x = $y 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*y] s ->4 - <1> ex-rv2sv sKRM*/129 ->5 4 <#> gvsv[*x] s/LVINTRO ->5 -e syntax OK

(Child has higher precedence than parent. LVINTRO = local)

It wouldn't work otherwise

Give local higher precedence >perl -le"$x=2; { (local $x)=$x; print $x; $x=3; print $x } print $x" 2 3 2 Give assignment higher precedence >perl -le"$x=2; { local ($x=$x); print $x; $x=3; print $x } print $x" 2 3 3 <-- XXX

I also see that '=' evaluates it's right side 1st.

Where did you see this? Operand evaluation order determines which operand is evaluated first. The operand evaluation order for = and other Perl binary operators is not documented anywhere and should probably be considered undefined.

Perhaps you looked up the associativity of the = operator. Associativity doesn't define which operand is evaluated first, it determines which operator is evaluated first when two operators of the same precedence are chained.

However, you are right that this feature of my and local is implemented by choosing a right to left operand evaluation order for assignment operators.

>perl -le"local(${print('a'), 'x'}) = ${print('b'), 'x'}; b a

Updated: Updated code into "precedence is irrelevant" reply.


In reply to Re^3: What's wrong with this local() ? by ikegami
in thread What's wrong with this local() ? by saintmike

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.