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.
|