perl如何遍历三组数组

如题,请给出简单例子或者思路,谢谢
2024-11-15 16:12:01
推荐回答(3个)
回答1:

@m=([[1,2,3],[2,3,4]],[[1,5],[2,6]]);
for $i(0..$#m)
{
for $j(0..$#{$m[$i]})
{
for $k(0..$#{$m[$i][$j]})
{
print $m[$i][$j][$k]," ";
}
}
}

回答2:

my @a=(1,2,3);
my @b=(4,5,6);
my @c=(7,8,9);
print "@a \n@b \n@c";

回答3:

my @a=(1,2,3);
my @b=(4,5,6);
my @c=(7,8,9);
foreach my $num(@a,@b,@c){
print "$num";
}