Here's most of the code for the problem I'm talking about:
@logs = <@ARGV>;
%reports=();
%results=();
open (INPUT_IN, "FindSitesInput.txt")|| die "Can't open input file! :$
+!";
while (defined($currentLine = <INPUT_IN>))
{
$_=$currentLine;
if(! m/^\#/)
{
#split currentLine into tab-delimited tokens
@tokens = split("\t",$currentLine);
my @temp = ($tokens[1], $tokens[2], $tokens[3], $tokens[4]);
$reports{$tokens[0]}=\@temp;
my @data=();
$results{$tokens[0]}=\@data;
}
}
}
close (INPUT_IN) || die "Can't close input file: $!";
#now run the reports on each log file
foreach $logfile(@logs)
{
open (LOG_IN, "$logfile")|| die "Can't open $logfile! :$!";
while (defined($currentLine = <LOG_IN>))
{
@tokens = split(" ",$currentLine);
foreach $rep (keys %reports)
{
@comparisons = split(" ", $reports{$rep}[0]);
foreach $item (@comparisons)
{
if($reports{$rep}[2] == "site")
{
$_=$tokens[6];
if(/$item/)
{
push @{$results{$rep}}, $currentLine;
}
}
elsif ($reports{$rep}[2] == "ip")
{
$_=$tokens[2];
if(/$item/)
{
push @{$results{$rep}}, $currentLine;
}
}
}
}
}
close (LOG_IN) || die "Can't close log file: $!";
#now write the output files for each report for this log
foreach $rep (keys %results)
{
open (OUTPUT, ">$logfile-$rep")|| die "Can't open $logfile-$re
+p! :$!";
print OUTPUT @{$results{$rep}};
if(close OUTPUT)
{
if(!($reports{$rep}[2]eq"none"))
{
system("c:\\blat\\blat $logfile-$rep -t \"$reports{$re
+p}[2]\"");
}
}
else
{
die "Can't close output file: $!";
}
}
}
The input values are read from a file (I've tested to verify that the data structure is created properly). |