以下是该文件的示例。假设我想解析第6列值并将它们存储在数组中。
42 test.example.com activityViewer/index.html 8a699fe62751d158dad57f6b9a3ae5a4 1291836592 4.1938788890839 4 test.example.com activityViewer/index.html ca0317343500ac35d46ca6b6bfe5918d 1291836592 4.224240064621 38 test.example.com activityViewer/index.html 2a473f02e814896af9d20ad333dfd5c5 1291836592 4.2302849292755 9 test.example.com activityViewer/index.html ac3942ad87fb0ce3efb034cdfc3d4c79 1291836592 4.2612450122833 31 test.example.com activityViewer/index.html 3497d90401e18483119b60a378bd8d27 1291836592 4.3139219284058 25 test.example.com activityViewer/index.html 377b12a86f6bbde33dc89e94cacd5246 1291836592 27.90621805191 3 test.example.com activityViewer/index.html 493bf2ba361b77d09305a14e9253322d 1291836592 29.722389936447
答案 0 :(得分:5)
你可以这样做:
use strict;
my @arr;
while(<>) {
my @tmp = split/\t/;
push @arr,$tmp[5];
}
并将脚本调用为:
$ perl myprg.pl file
或者,您可以将文件视为CSV,并使用tab作为字段分隔符,并使用合适的CSV解析器模块。
答案 1 :(得分:0)
答案 2 :(得分:0)
拆分将是最简单的方法
my @ary;
foreach my $line (split(/\n/, $full_text)) {
my @l = split(/\t/, $line);
push @ary, $l[5]
}