Pharao
20.09.2004, 16:56
Hi
das ist mein log.pl - Testfile, dass ausgewertet wird.
warn an warning occured
error an error occured
hier gibts nix
alles ok
ok hier auch
nana
Das ist mein Quellcode
#!/usr/bin/perl
#Tags 2 Highlight
@warntags = ('warn', 'error');
@okaytags = ('ok');
#colors...
$red = "<span class=\"red\">";
$blue = "<span class=\"blue\">";
$closespan ="</span>";
#Output
@tagoutput; #Outputarray
$linecount="0"; #Outputentry
#Template: Top of the HTML-File
my $toptemp = <<HERE_TOPTEMP;
<html>
<head>
<title>LogBock-Analyse</title>
</head>
<body>
HERE_TOPTEMP
#Template: Bottom of the HTML-File
my $bottemp = <<HERE_BOTTEMP;
</body>
</html>
HERE_BOTTEMP
my $logfile = "log.pl";
open(LOG, "< $logfile");
#Mainpart: file parsen
while (my $line = <LOG>)
{
#split file at new line
chomp ($line);
@LinesOfLog = (split("\n", $line));
#check every line in logfile
foreach $logentry (@LinesOfLog)
{
#check log for warntags
foreach $tagentry (@warntags)
{
$found = grep /$tagentry/, $logentry;
#if warntag is found -> do
if($found == 1)
{
$tagoutput[$linecount] = $red . $found . $closespan . "<br>\n";
}
}
#check log for okaytags
foreach $tagentry (@okaytags)
{
$found = grep /$tagentry/, $logentry;
#if okaytag is found -> do
if($found == 1)
{
$tagoutput[$linecount] = $blue . $found . $closespan . "<br>\n";
}
}
#if no tag is found -> do defaultaction
if($found != 1)
{
$tagoutput[$linecount] = $logentry . "<br>\n";
}
#Increase HTMLlines
$linecount += 1;
}
}
for ($i = 0; $i < @tagoutput; $i++)
{
print $tagoutput[$i] . "\n";
}
Und das ist die Ausgabe auf dem Terminal
[blitz@GoldSpirit blitz]$ perl LogBock.pl
warn an warning occured<br>
error an error occured<br>
hier gibts nix<br>
<span class="blue">1</span><br>
<span class="blue">1</span><br>
nana<br>
Leider kann ich mir nicht erklären, wo der Fehler beim zusammenführen der Strings liegt.
Die Aufrufe sind ja genau gleich, aber einmal wird "span" ignoriert und einmal wird $found
verfälscht.
Findet jemand beim überfliegen das Problem?
gruß
Pharao
das ist mein log.pl - Testfile, dass ausgewertet wird.
warn an warning occured
error an error occured
hier gibts nix
alles ok
ok hier auch
nana
Das ist mein Quellcode
#!/usr/bin/perl
#Tags 2 Highlight
@warntags = ('warn', 'error');
@okaytags = ('ok');
#colors...
$red = "<span class=\"red\">";
$blue = "<span class=\"blue\">";
$closespan ="</span>";
#Output
@tagoutput; #Outputarray
$linecount="0"; #Outputentry
#Template: Top of the HTML-File
my $toptemp = <<HERE_TOPTEMP;
<html>
<head>
<title>LogBock-Analyse</title>
</head>
<body>
HERE_TOPTEMP
#Template: Bottom of the HTML-File
my $bottemp = <<HERE_BOTTEMP;
</body>
</html>
HERE_BOTTEMP
my $logfile = "log.pl";
open(LOG, "< $logfile");
#Mainpart: file parsen
while (my $line = <LOG>)
{
#split file at new line
chomp ($line);
@LinesOfLog = (split("\n", $line));
#check every line in logfile
foreach $logentry (@LinesOfLog)
{
#check log for warntags
foreach $tagentry (@warntags)
{
$found = grep /$tagentry/, $logentry;
#if warntag is found -> do
if($found == 1)
{
$tagoutput[$linecount] = $red . $found . $closespan . "<br>\n";
}
}
#check log for okaytags
foreach $tagentry (@okaytags)
{
$found = grep /$tagentry/, $logentry;
#if okaytag is found -> do
if($found == 1)
{
$tagoutput[$linecount] = $blue . $found . $closespan . "<br>\n";
}
}
#if no tag is found -> do defaultaction
if($found != 1)
{
$tagoutput[$linecount] = $logentry . "<br>\n";
}
#Increase HTMLlines
$linecount += 1;
}
}
for ($i = 0; $i < @tagoutput; $i++)
{
print $tagoutput[$i] . "\n";
}
Und das ist die Ausgabe auf dem Terminal
[blitz@GoldSpirit blitz]$ perl LogBock.pl
warn an warning occured<br>
error an error occured<br>
hier gibts nix<br>
<span class="blue">1</span><br>
<span class="blue">1</span><br>
nana<br>
Leider kann ich mir nicht erklären, wo der Fehler beim zusammenführen der Strings liegt.
Die Aufrufe sind ja genau gleich, aber einmal wird "span" ignoriert und einmal wird $found
verfälscht.
Findet jemand beim überfliegen das Problem?
gruß
Pharao