in reply to Re^2: Accessing Arguments inside Subroutines via @_
in thread Accessing Arguments inside Subroutines via @_
Hello citi2015,
I meant Perl’s design decision to remove the aliasing when @_ is assigned-to within a subroutine.
You can, of course, do the swap by explicitly accessing the subroutine arguments as individual elements of @_:
sub swap { my $temp = $_[0]; $_[0] = $_[1]; $_[1] = $temp; }
— but note the necessity of “remembering” the initial value of $_[0] by storing it in a temporary variable. And I think that answers my question: if the aliasing were not removed, @_ = reverse @_ would produce wrong results, because some elements would be changed (assigned-to) before they were assigned-from.
Hope that helps,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Accessing Arguments inside Subroutines via @_
by LanX (Saint) on Mar 20, 2015 at 21:11 UTC | |
by Athanasius (Archbishop) on Mar 21, 2015 at 03:24 UTC | |
by LanX (Saint) on Mar 21, 2015 at 12:09 UTC | |
by Athanasius (Archbishop) on Mar 22, 2015 at 08:28 UTC | |
Re^4: Accessing Arguments inside Subroutines via @_
by roboticus (Chancellor) on Mar 20, 2015 at 22:35 UTC |