如何在Perl中存储列(在制表符分隔的文本文件中)中的值

kam*_*mal 0 perl parsing

这是该文件的一个示例.假设我想解析第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

cod*_*ict 5

你可以做:

use strict;

my @arr;    
while(<>) {
        my @tmp = split/\t/;
        push @arr,$tmp[5];
}
Run Code Online (Sandbox Code Playgroud)

并将脚本调用为:

$ perl myprg.pl  file
Run Code Online (Sandbox Code Playgroud)

看见

或者,您可以将文件视为CSV,并使用制表符作为字段分隔符,并使用合适的CSV解析器模块.