sub x { (1 , 2 , 7); } sub z { my @L = (1 , 2 , 7); @L } my $x = x; warn $x; my $z = z; warn $z;
This can be useful when you have a sub that was written to return a scalar but you need to return more from it: just return a list and have the last element be what it used to return and put all the new things you want to return from it in a list in front of it:
sub x { ($new_val, $new_val2, $old_value_returned_when_called_in_scalar_cont +ext);
Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality
update (broquaint): shortened title (was A list returns its last, an array returns its weight (keeping a subroutine which used to return a scalar useable when you need to return more))
|
---|