【发布时间】:2013-08-05 00:45:44
【问题描述】:
我正在读取一个名为mention-freq 的文本文件,其中包含以下格式的数据:
1
1
13
2
我想读取这些行并将值存储在一个数组中,如下所示:@a=(1, 1, 13, 2)。 Perl push 函数给出了索引值/行号,即 1,2,3,4,而不是我想要的输出。你能指出错误吗?这是我所做的:
use strict;
use warnings;
open(FH, "<mention-freq") || die "$!";
my @a;
my $line;
while ($line = <FH>)
{
$line =~ s/\n//;
push @a, $line;
print @a."\n";
}
close FH;
【问题讨论】:
-
我喜欢
twoHandsTwoCutsFunction函数:)sub{map{s/^\s+//; s/\s+$//; $_}@_}