in reply to Re: Will "$_[0]=shift" always resolve shift first?
in thread Will "$_[0]=shift" always resolve shift first?
I was going to say Perl always evaluates operands in left to right order, but it's not the case.
It does, unless precedence or associativity gets in your way. Your example demonstrates this quite well:
var() = foo() + bar() * baz(); 6 1 2 3 7 5 4 Precedence tightest: * + loosest: =
So the arguments are evaluated left-to-right on the LHS of the =, then the sub expressions in order of their precedence, then the RHS. (perltrap documents that the RHS is evaluated first, btw).
Update: the more I think about this, the less sure I am. So try not rely too much on it ;-)
In short, you might be able to rely on the order in which operands are evaluated, but I consider it a bad practice
Fully agreed.
Second update
Ok, the operands are evaluated left-to-right, the operators according to their precedence/associativity.
The assignment operator is an exception (on which we rely quite often).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Will "$_[0]=shift" always resolve shift first?
by ikegami (Patriarch) on Sep 08, 2008 at 22:14 UTC | |
by tilly (Archbishop) on Sep 09, 2008 at 00:47 UTC | |
by ikegami (Patriarch) on Sep 09, 2008 at 02:03 UTC | |
by ikegami (Patriarch) on Sep 09, 2008 at 00:54 UTC | |
by tilly (Archbishop) on Sep 09, 2008 at 01:02 UTC | |
by ikegami (Patriarch) on Sep 09, 2008 at 01:08 UTC | |
by moritz (Cardinal) on Sep 08, 2008 at 22:28 UTC | |
by ikegami (Patriarch) on Sep 08, 2008 at 22:55 UTC |