I would like to create a logfile viewer in Perl Tk that can use a pipe to get input from another program's STDOUT.
For instance:
$> tail -f logfile | logfileviewer
- or -
$> ls -l | logfileviewer
I have a while loop to get <STDIN> as seen below:
#!/usr/local/bin/perl -w
use Tk;
use Tk::HList;
use Tk::ItemStyle;
$|=1;
########################
# Text Window
my $mw2 = MainWindow->new;
$mw2->title("LogViewer");
my $tex = $mw2->Scrolled("Text",
-background => 'grey',
-foreground => 'white'
)->pack(
-fill => 'both',
-expand => 1,
);
#create text tag
$tex->tagConfigure('red', -foreground => 'red' );
Tk::MainLoop;
sub DisplayItem {
print "Called DisplayItem\n";
$tex->insert("end", "$_[0]", 'red' );
}
while( <STDIN> ) {
print "While called with: $_\n";
chomp;
&DisplayItem( $_ );
} # end while
However, I only get the following error when closing the MainWindow:
While called with: random text in file
Called DisplayItem
Failed to AUTOLOAD 'Tk::Frame::insert' at logviewer line 37
Any assistance would be appreciated. Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.