in reply to Re: shift vs @_
in thread shift vs @_
I can't easily do my $x, $y = @_; It's valid perl. It assigns a scalar.
Only because the way you called my creates a scalar context. Try my( $x, $y ) = @_;, which creates a list context, and so produces the same result as my $x = $_[0]; my $y = $_[1];.
This works with any array or list. Check out the difference between:
$x, $y, $z = (2,3,4); # $x = undef, $y = undef, $z = 4 ($x, $y, $z) = (2,3,4); # $x = 2, $y = 3, $z = 4
See, a list in scalar context will give its last element. An array in scalar context will give the number of its elements. However, if we make both sides of the assignment have list context, then elements get copied.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: shift vs @_
by exussum0 (Vicar) on Oct 06, 2006 at 14:39 UTC | |
by radiantmatrix (Parson) on Oct 06, 2006 at 16:36 UTC | |
by exussum0 (Vicar) on Oct 06, 2006 at 20:01 UTC |