in reply to Will "$_[0]=shift" always resolve shift first?
I've found the following code in Perl 5.10.0's testsuite in t/op/local.t:
@a = ('a', 'b', 'c'); { local($a[1]) = 'foo'; local($a[2]) = $a[2]; is($a[1], 'foo'); is($a[2], 'c'); undef @a; }
Now, I daresay (and I hope that my head is clearer than when I wrote my last node) that this only works if "=" evaluates its right-hand operand first.
The important line is the one with the second local. As a run-time operator, local() effectively sets its operand ($a[2] in this case) to an undefined value. But then this new value will be set to the value of $a[2] before local was executed. This would not work the other way round.
Apart from this extract, local.t contains more similar tests.
In a nutshell: Even though I could not find any hints in the documentation, the test suite suggests that kyle's coworker's code is reliable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Will "$_[0]=shift" always resolve shift first?
by ikegami (Patriarch) on Sep 09, 2008 at 00:18 UTC |