in reply to Subroutines and Passing data ...
There are a couple of different ways to do this.
## 1. As an array sub one { return ( $val1, $val2 ); } my @ar = one(); print $ar[0], $ar[1]; ## 2. As an arrayref sub two { return [ $val1, $val2 ]; } my $aref = two(); print $aref->[0], $aref->[1]; ## 3. As a hashref sub three { return { val1 => $val1, val2 => $val2 }; } my $href = three(); print $href->{ 'val1' }, $href->{ 'val2' };
I'm sure there are other ways too, but these are commonly the way I do it. I would suggest 3. for unrelated values, and 1. only if you actually want to return an array of similar values.
-Bryan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Subroutines and Passing data ...
by tphyahoo (Vicar) on Jun 13, 2005 at 14:07 UTC | |
|
Re^2: Subroutines and Passing data ...
by salva (Canon) on Jun 13, 2005 at 13:43 UTC |