to myself 的分类学习日志

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

Perl日志分析

Posted on 2010-09-30 16:29 kongkongzi 阅读(540) 评论(0)  编辑 收藏 引用 所属分类: perl
#!/usr/bin/perl -w
# file: statslog 


use strict;

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

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


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

my @arrTag = (
        
"Hello,world!",
    );

#print $arrTag[0], "\n";
#print $#arrTag, "\n";
#print $arrTag[$#arrTag], "\n";


my $user = "myname";
my $matchStr;

my $usermin = $ARGV[2];
my $usermax = $ARGV[3];

for (my $j = $usermin - 1$j < $usermax$j++)
{
    
$matchStr = sprintf("%s%d %s", $user, $j+1, $arrTag[0]);

    
my $bMatch = 0;

    
seek(INLOG, 0, 0);
    
while (<INLOG>
    {
        
if (/$matchStr/)        # $_
        {
        
#    print;
        #    print STATSOUT;

            $bMatch = 1;
            
last;
        }
    }

    
if (0 == $bMatch)
    {
        
print STATSOUT "NOt match", $matchStr, "\n";
    }
}


close INLOG;
close STATSOUT;


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理