w**2 发帖数: 724 | 1 so i have a code like this,
foreach my $row (@lines)
{
my ($v1, $v2) = @$row;
# a lot of logics here
print $v1." ---- ".$v2."n";
}
for whatever reason, i want to reuse this piece of code for different places
,
say i have 5 lines, how to make my function return 2D array like this ?
{(1,1), (2,2), (3,3), (4,4), (5,5)}
Thanks ! | e*******o 发帖数: 4654 | | w**2 发帖数: 724 | 3 have a deadline to meet in 2 days, no time to learn, mangers won't give the
time to learn, this is my life.
a package might be better
【在 e*******o 的大作中提到】 : http://perldoc.perl.org/perldsc.html : 这本书的前几章 : http://it-ebooks.info/book/879/ : 买本perl的书翻翻,比如这边,就几块钱。 : http://www.amazon.com/Perl-Cookbook-Second-Tom-Christiansen/dp/ : 你想搞好Perl 这边一定要买过来。 : http://www.amazon.com/Programming-Perl-Edition-Larry-Wall/dp/05 : 过一遍,基本上不会再有啥问题了。 : Perl 那么老的语言,你能遇到的问题,基本上都讨论过了。
| e*******o 发帖数: 4654 | 4 my $arr_of_arr;
in the loop,
push @$arr_of_arr, [$v1, $v2];
at the end
return $arr_of_arr | w**2 发帖数: 724 | 5 多谢!
【在 e*******o 的大作中提到】 : my $arr_of_arr; : in the loop, : push @$arr_of_arr, [$v1, $v2]; : at the end : return $arr_of_arr
|
|