有人能告诉我如何一起使用2个阵列以特定方式打印吗?
@array1= "in_1","in_2","in_3";
@array2= "1","0","1";
我希望它们以这种模式打印
in_1 = 1; in_2 = 0; in_3 =1 ;
感谢
答案 0 :(得分:1)
print map "$array1[$_] = $array2[$_]; ", 0 .. $#array1;
答案 1 :(得分:0)
可以使用哈希切片(关联数组)
@ary1 = (a,b,c);
@ary2 = (1,2,3);
%hash = ();
@hash{@ary1} = @ary2;
foreach $key ( keys %hash )
{
print "$key = $hash{$key}\n";
}
或者只是一个简单的循环。
for (0 .. $#ary1)
{
print "$ary1[$_] = $ary2[$_]\n";
}