In perl 5 all order of evaluation is undefined
Not true. There are a few cases for which order of execution is very well defined. One is your example, assignment: the assignment always happens after the expression, the RHS is calculated. That makes sense, as it's only at that point that the value is known.

And two is the shortcircuit operators, and/or and &&/||. The right hand side isn't even calculated if the left hand side is all one needs to know to get the final result of the whole expression.

So this combination is very safe:

sub foo { return 3+$a }; $a = 1; $a = foo($a) and print $a;
Order of evaluation is as follows:

Note that this is different from the following case:

$\ = "\n"; my $x = 12; { my $x = $x + 1; # <--- point of interest print $x; } print $x;
Note that in the relevant statement, $x in the left hand side and in the right hand side are actually two different variables, both named $x. The RHS uses the outer scoped variable, the LHS the inner scoped variable. And even though here:
my $x = 123; { my $x = 45 and print $x; }
the assignment does happen before the print, it prints the outer scoped variable, because that's the variable the parameter refers to.

In reply to Re: Matching and order of evaluation by bart
in thread Matching and order of evaluation by diotalevi

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.