return 2-dimension array

return 2-dimension array

return 2-dimension array
How to return 2-dimension array from a subroutine using reference ?

hasty!!!



the following code dosen't work

$a = \@aa ;
return $a;

.....

@bb = @$a;

print @bb , erro:r $bb is not initiated.

Why ?

How to solve the problem?

ps: my array is large

Thanks a lot


@bb=@$a just copied your.
@bb=@$a just copied your large array @aa,so it's useless if you want to process your large array more efficiently...
in your codes,the subroutine just returned a reference to your large array @aa, so, what you need to do next is just use a scalar( for example: $arrayref ) to store the array reference returned by your subroutine,and then, you could process the large array via the array reference [b]$arrayref[/b];
you'd better to read the tutorial of [url=http://perldoc.perl.org/perlreftut.html]perlreftut[/url] :-).

for example:
[quote]
$arrayref = sub_of_faint();

for $i ( 0..$#{$arrayref} ){
for $j ( 0..$#{$arrayref->[$i]} ){
print "[$i,$j] = $arrayref->[$i][$j] \n";
}
}


sub sub_of_faint {
@array_of_faint = ([a..f],[1..6]);
$scalar_of_faint = \@array_of_faint;
return $scalar_of_faint;
}

[/quote]
presents:[quote][0,0] = a
[0,1] = b
[0,2] = c
[0,3] = d
[0,4] = e
[0,5] = f
[1,0] = 1
[1,1] = 2
[1,2] = 3
[1,3] = 4
[1,4] = 5
[1,5] = 6
[/quote]




   

Your code can work well..
Your code can work well. This is sure. I will make a try on my array. Thank you very much.