二维数组的几种输出方法:
my @array1=([1,2,3,4,11,12],[5,6],[7,8,9]);
for(my $i=0;$i<=$#array1;$i++){ for(my $j=0;$j<=$#{$array1[$i]};$j++){ #注意内循环的写法 print "$array1[$i][$j] "; } print "\n"; } my @array2=([1,2,3,4,11,12],[5,6],[7,8,9]); for $i (0 .. $#array2){ for $j (0 .. $#{$array2[$i]}){ print "$array2[$i][$j] "; } print "\n"; } my @array3=([1,2,3,4,11,12],[5,6],[7,8,9]); for $i (0 .. $#array3){ $aref=$array3[$i]; for $j (0 .. $#{$aref}){ print "$array3[$i][$j] "; } print "\n"; } my @array4=([1,2,3,4,11,12],[5,6],[7,8,9]); for $i (0 .. $#array4){ $aref=$array4[$i]; $n=@$aref-1; for $j (0 .. $n){ print "$array4[$i][$j] "; } print "\n"; }