[Chicago-talk] return values
Andy Lester
andy at petdance.com
Tue Dec 30 14:07:54 CST 2003
> if you have multiple return values do you have to use an array to collect
> them? or can you get each return value in is own variable off the jump?
>
> sub stuff {
> $a=1;
> $b=2;
> return ($a, $b);
> }
That's fine. Then, you:
my ($x,$y) = stuff();
or
my @values = stuff();
You can also only get one value back if you want, like so:
my ($x,undef) = stuff();
or
my ($x) = stuff();
Make sure you do NOT do
my $x = stuff(); # $x now == 2
because $x is in scalar context, and a list assigned to a scalar returns
the length of the list.
xoa
--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance
More information about the Chicago-talk
mailing list