Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Re: POE, was Re: Tk tail -f - How?

by BrowserUk (Pope)
on Oct 09, 2003 at 12:43 UTC ( #297895=note: print w/replies, xml ) Need Help??

in reply to Re: POE, was Re: Tk tail -f - How?
in thread Tk tail -f - How?

You might want to add a check for the number of lines you have in the listbox and limit it to some reasonable size.

If your file grows quickly, you could rapidly find yourself running out of memory, and (if my limited experience of Tk is still valid) things start to slow down when widgets grow beyond a certain size.

It would be more efficient to load the listbox using

$listbox->insert( 'end', <F> ); $listbox->see( 'end' ); $mw->update();

Also, you probably shouldn't be seeking to the end after you have read. If nothing has been added, it will make no difference as you will already be there. However, if something was added between the last read and the seek, you will never read it and lines (or partial lines) will be lost..

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Re: POE, was Re: Tk tail -f - How?
by msemtd (Scribe) on Oct 09, 2003 at 13:38 UTC
    Of course :) after insert task I have added...
    my $trim = $listbox->size - $maxlines; $listbox->delete(0, $trim-1) if trim > 0;
    I accept the point re last-read-to-seek-delay-data-loss: any ideas anyone?

    Otherwise I don't see any harm with the seek(F,0,1) - isn't it required in order to clear the EOF condition as per docs?

      any ideas anyone?

      What my one-liner above demonstrated was that if you read the file with the diamond operator, the way you detect eof, is when it returns undef. If you simply ignore the undefs and continue reading, the eof condition clears itself without any further action required..

      Given the docs you cite, I'm not sure if this is "working as designed" or an an undocumented and therefore unreliable feature, but it has worked this way in every version of perl I've used. About the oldest script I have that I still use makes use of this feature.

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://297895]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2020-12-04 05:55 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (58 votes). Check out past polls.