Hello LanX,
Thanks for that, it’s good to know. Perl continues to surprise! I looked in the Camel Book, but the section on “List Assignment”1 doesn’t cover this behaviour. Do you know where it’s documented?
I’m intrigued to know how Perl accomplishes this. I wrote the following, but it left me none the wiser:
#! perl use strict; use warnings; use feature qw(say state); #say 'f = ', f(), ', g = ', g(); ( f(), g() ) = ( g(), f() ); #say 'f = ', f(), ', g = ', g(); sub f : lvalue { state $f = 'first'; say 'f(', $f, ')'; return $f; } sub g : lvalue { state $g = 'second'; say 'g(', $g, ')'; return $g; }
Output:
12:58 >perl 1193_SoPW.pl g(second) f(first) f(first) g(second) 12:58 >
It looks as though the virtual machine:
So it must create temporary copies of the right-hand variables “under the hood”?
1Chapter 2, pages 82–83 in the 4th Edition.
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^5: Accessing Arguments inside Subroutines via @_
by Athanasius
in thread Accessing Arguments inside Subroutines via @_
by citi2015
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |