有下一个 perl 代码
use 5.012;
use warnings;
#make some random numbers
my @list = map { rand } 1..10;
say "print all 10 numbers";
say $_ for @list;
say "print only first 5";
my $n=0;
for (@list) {
say $_ if $n++ < 5;
}
用于打印任何数组的第一个(最后一个)N 个元素的更紧凑的形式?
接下来是语法错误...
$n=0;
#say $_ if($n++ < 5) for @list;