return (@array1, @array2);
This will result in list flattening. One big list.
I read something about passing by reference
Take references to the arrays.
return (\array1,\array2)
Perl comes with extensive online tutorials/documentation.
but does not found anything on return by references.
See perldoc perlref
perldoc perlreftut
alfred,
Khairul Azmi wrote:
Hi,
I'm trying to write a function that could return two arrays.
sub func {
my @array1=(1,2,3,4);
my @array2=(a,b,c,d);
return (@array1, @array2);
}
my (@out1,@out2)=func();
for (my $i=0;$i<@out1;$i++) {
print "$out1[$i]";
}
print "\n";
for (my $i=0;$i<@out2;$i++) {
print "$out2[$i]";
}
print "\n";
The program would store everything onto @out1 and leave nothing to @out2
1234abcd
I read something about passing by reference but does not found
anything on return by references.
Help please. Thanks in advance.
--