to myself 的分类学习日志

做自己想做的事
posts - 232, comments - 6, trackbacks - 0, articles - 0

Perl文本分析

Posted on 2010-08-09 17:58 kongkongzi 阅读(406) 评论(0)  编辑 收藏 引用 所属分类: perl
#!/usr/bin/perl -w
# file: statstxt


use strict;

if (@ARGV < 2# @ARGV return size of array ARGV in this context
{
        
die "Usage: $0 intxt outfile\n";
}


my $success = open INTXT, "<", $ARGV[0];        # open function has three args, INTXT is a file handler
if (!$success)
{
        
die "Cannot open $ARGV[0]:$!";
}

$success = open STATSOUT, ">", $ARGV[1];
if (!$success)
{
        
die "Cannot open $ARGV[1]:$!";
}


while (<INTXT>)
{
        
my @arrCol = split(/\s+/);      # $_    # split $_ by spaces
        if ($arrCol[1> 0)             # The second column of text
        {
                
print;
                
print STATSOUT;
        }

}


close INTXT;
close STATSOUT;