Posted on 2010-09-30 16:29
kongkongzi 阅读(554)
评论(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;