Hi folks.
I have spent half the afternoon looking on websites and trying to figure out this problem, but to no avail.
I have written a chunk of code, that, using Tk, should read my logfile, and then whack it into the window. This code works fine, see below.
#!/sbcimp/run/pkgs/gsbl/bin/perl -w
#!/sbclocal/bin/perl -w
#use strict;
use Tk;
# open filehandle
open (LOG, "commandpost.log") || die "Could not open file : $!\n";
#####
#
# Main Window
#
#####
my $mw = MainWindow->new();
# add label
$mw->Label(-text => "CMD_POST Error Catcher")->pack;
#####
#
# Menubar
#
#####
my $menubar = $mw->Frame(-relief => "ridge",
-borderwidth => 2)->pack (-anchor => "nw", -fill => "x");
# add file option to menubar
my $filemenu = $menubar->Menubutton(-text => "File",
-underline => 1)->pack (-side => "left");
# add separator
$filemenu->separator();
# add help menu
my $helpmenu = $menubar->Menubutton(-text => "Help",
-underline => 1)->pack (-side => "left");
# add separator
$helpmenu->separator();
# add about option
$helpmenu->command(-label => "About...",
-underline =>1, -command => \&help_about);
#####
#
# Main Text Box
#
#####
my $listbox = $mw->Listbox(-relief => "sunken", -width => 170, -height
+ =>30,
-background => "white");
# scrollbar
my $scrollbar = $mw->Scrollbar(-command => ["yview", $listbox]);
$listbox->configure(-yscrollcommand => ["set", $scrollbar]);
# set listbox internal colour
$listbox->configure(-background => "LightBlue2");
# set main window colour
$listbox->setPalette("LightBlue1");
$listbox->pack(-side => "left", -fill => "both", -expand => "yes");
$scrollbar->pack(-side => "right", -fill => "y");
# loop and subroutine to enter text from logfile into listbox
$mw->fileevent(LOG, 'readable', [\&insert_lines]);
MainLoop;
#####
#
# Subroutines
#
#####
sub insert_lines
{
my $logline;
if ($logline =<LOG>) { $listbox->insert('end', $logline);
$listbox->yview('moveto'
+,100);
#format_text();
} else
{
$mw->fileevent(LOG, 'readable
+', "");
}
}
Okay, so now I have tried to get clever. I want to put in a little chunk that goes, okay, look at each line, and if one contains the word CRITICAL, print it to the listbox in red, and if one contains the word MAJOR, print it to the listbox in orange.
my $textline;
while ($textline = <LOG>) {
if ($textline =~ /CRITICAL/) {
$listbox->configure(-foreground => "red2");
} elsif ($textline =~ /MAJOR/) {
$listbox->configure(-foreground => "DarkOrange2");
} else {
}
}
$mw->fileevent(LOG, 'readable', [\&insert_lines]);
So i figure this bit of code will do the trick. Alas, but no. All that happens is now I get a blank listbox. I thought by putting it before
$mw->fileevent(LOG, 'readable', [\&insert_lines]); I wouldn't be screwing up the loop that reads the text file.
HEEEEEEEEEELP! If anyone knows anything about Tk, I would really appreciate it. And I did search here and on CPAN. A lot.
Thanks, ML
if ($mr_leisure) { bow; }
this is still not finished