Marwell_Wildlife has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code (copied from a post in 2009) <c> #!/usr/bin/perl -- use strict; use warnings; use Tk; my $mw = tkinit(); my $l = $mw->Scrolled(qw' Text -height 2'); $mw->Button( -text => 'add', -command => sub { $l->insert( 'end', localtime() . "\n" ); $l->see('end'); } )->pack; $l->pack; $l->insert( 'end', "hi\nthere\n" ); MainLoop();

...which works fine as a demo - but I need to add to the scolling box more or less infinitely (long running app logging diags to the scroll area) - presumably this will slowly use more and more memory as text lines are added...

is there some way to have the scrolling box as a sort of FIFO with just a few hundred lines in the "history" ?

thanks
dave

20100504 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: TK infinite scrolling?
by AnomalousMonk (Archbishop) on Apr 29, 2010 at 11:14 UTC

    And use  index to find number of lines.

    >perl -wMstrict -le "use Tk; use constant HEIGHT => 7; my $mw = tkinit(); my $l = $mw->Scrolled(qw'Text -height', HEIGHT); $mw->Button( -text => 'add', -command => sub { $l->insert('end', localtime() . qq{\n}); $l->insert('end', $l->index('end') . ' '); $l->insert('end', int($l->index('end')) . qq{\n}); $l->delete('1.0', '2.0') while int($l->index('end')) > 2 * HEIGHT; $l->see('end'); }, )->pack; $l->pack; $l->insert('end', qq{hi\nthere\n}); MainLoop(); "

    And ditto choroba: Please use  <c> tags. Please see Markup in the Monastery.

Re: TK infinite scrolling?
by choroba (Cardinal) on Apr 29, 2010 at 10:41 UTC

    Please, format your code with <code> tags.

    And yes, it is possible. Similarly to insert, you can use delete.