Here is a version with fileevent that works (with some problems):

# insert widget code here open (LOG, "tail -f log.log|") || die "Nope : $!"; $mw->fileevent(\*LOG, 'readable', \&insert_lines); MainLoop(); sub insert_lines { my $line; if(defined($line = <LOG>)){ if( $line =~ /(CRITICAL|MAJOR)/){ $text->insert('end',$line,$1); } else { $text->insert('end',$line); } }else{ $mw->fileevent(\*LOG, 'readable',''); } }

The problem being (on my machine) that it sometimes doesn't update even there is data waiting on the pipe. Even the first time it only gets the first line of the tail, then nothing until another line is added to the file (then it gets the remainder of the tail and the newer line). You could work around this using repeat() to check the file yourself every so often -- here's a quicky example that might suffice for your needs:

# insert widget code here open (LOG, "log.log") || die "Nope : $!"; load_file(5); $mw->repeat(5000,\&tail_file); # check every 5 seconds MainLoop(); sub load_file { my $n = shift || 10; #how many lines to initially tail my @tail; while(<LOG>){ shift @tail if $#tail > $n; push @tail, $_; } for(@tail){ if(/(CRITICAL|MAJOR)/){ $text->insert('end',$_,$1); } else { $text->insert('end',$_); } } } sub tail_file { seek(LOG,0,1); while(<LOG>){ if(/(CRITICAL|MAJOR)/){ $text->insert('end',$_,$1); } else { $text->insert('end',$_); } } }

In reply to Re: Re: Re: TK Problem (me again) by danger
in thread TK Problem (me again) by locked_user mr_leisure

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.