#!/usr/bin/perl use strict; use warnings; use Tk; require "./SFDTail.pm"; . . # SFDTail.pm is our file handling package my $tailer = SFDTail::new(); my $mw = MainWindow->new(); my $txtarea = $mw->Scrolled('Text', ... option stuff ...); . . MainLoop; . . # grabtext() is our Tk::fileevent callback function # $tailer->fh() returns a file handle ($fh), created as: # open($fh, "tail -f -n 20 $self->{file} |"); sub grabtext { # $stuff = <$tailer->fh()> don't work --?? my $glob = $tailer->fh(); my $stuff = <$glob>; $txtarea->insert('end', $stuff); $txtarea->yview('end'); } . . # Tk::Button event callback: select appropriate file, let $tailer open it. # $tailer->tail($file) is where the file gets opened, as above. sub standard { my $unit = shift; # typically 'Unit01', 'Unit02', etc # clean up: close any previous filehandle and kill any tail PID's $tailer->closepipe(); my $file = "/usr/local/scripts/tk/${unit}.txt"; $txtarea->delete('1.0', 'end'); # if data input not active, the file may not be there if ( -f $file ) { if ( $tailer->tail($file) ) { $mw->fileevent($tailer->fh(), 'readable' => \&grabtext); } } else { $txtarea->insert('end', "\n No data for $unit. \n"); } }