You say you think it's defined, but the only thing you gave to back that up is that other things aren't defined. Please show where it is defined if it is.
The operand evaluation order is well known* for all operators, but it's only documented for some. It's not for the arrow operator (docs below). Off the top of my head, operand evaluation order is only defined for the following operators:
- logical operators (for short-circuiting)
- conditional operator (for short-circuiting)**
- comma/list operator (so it can be used as a statement separator)
- assignment (for my $x = $x; and local $x = $x;)***
From perlop:
"->" is an infix dereference operator, just as it is in C and C++. If the right side is either a [...], {...}, or a (...) subscript, then the left side must be either a hard or symbolic reference to an array, a hash, or a subroutine respectively. (Or technically speaking, a location capable of holding a hard reference, if it's an array or hash reference being used for assignment.) See perlreftut and perlref.
Otherwise, the right side is a method name or a simple scalar variable containing either the method name or a subroutine reference, and the left side must be either an object (a blessed reference) or a class name (that is, a package name). See perlobj.
As you can see, there's no mention of operand evaluation order.
* — Meaning all existing versions of Perl use the same order.
** — Short-circuiting nature and thus operand evaluation order is not actually documented, but it is strongly expected.
*** — Operand evaluation order is inferred from documented ability to do my $x = $x; and local $x = $x;.
| [reply] [d/l] [select] |
You're say you think it's defined, but the only thing you gave to back that up is that other things aren't defined. Please show where it is defined if it is.
...As you can see, there's no mention of operand evaluation order.
And despite this, you understand the left hand side has to be evaluated before the right
I really don't care if/where it is documented, it has been used this way since there was a perl5, in core modules since at least perl-5.002, 15 years ago, and in perltoot since about perl-5.004, 14 years ago
| [reply] |
Did you read what you linked to?
And despite this, you understand the left hand side has to be evaluated before the right
Quite the opposite, I understand the this isn't true at all. Perl is free to place the contents of @_ on the stack before evaluating the shift(@_).
There's nothing in the linked post to support your statement. It states what Perl *does*, not what Perl *must do*. In fact, it contradicts your statement because it specifically points out that other behaviours are possible.
and in perltoot since about perl-5.004, 14 years ago
uh, nowhere in perltoot or in the other document you linked is @_ both used and modified in the same statement, much less the more specific shift->foo(@_).
In case there's any confusion, shift->foo() and $class->foo(@_) are perfectly safe, it's shift->foo(@_) that's not.
| [reply] [d/l] [select] |