从2D数组打印行

时间:2015-05-11 00:37:54

标签: arrays perl

#!/usr/bin/perl   
use strict;
use warnings;
my @array = (
    [1,2,3,4],
    [5,6,7,8]
);
my @second_row = @{ $array[1] };
print "Second row: [@second_row]\n";

输出为:第二行:[5 6 7 8]
但我需要它:第二行:[5,6,7,8]

1 个答案:

答案 0 :(得分:4)

你想要的是the join function。尝试类似:

print "Second row: [", join(', ', @second_row), "]\n";