Here is a test I ran awhile back to see if HList leaked memory with rapid updates. It passed the test. I don't have a Tk:repeat in this code, but it shows how to do updates without memory gains. If you want to add and remove rows dynamically, I suggest you use the $HLIST->hide( ) method, rather than attemping to delete and recreate the rows and columns, for the same reason of internal memory buildup of crud left over from old rows and columns.

All I'm saying, is watch for memory gains, and do it often, before your script gets too complex.

#!/usr/bin/perl use strict; use Tk; use Tk::HList; use YAML; #use MeM; #demonstrates the internal counter of HList #and why it is better to reconfigure entries #rather than deleting them and adding new my $mw = MainWindow->new(); #create some sample data my %data; foreach (0..100) { $data{$_}{'name'} = 'name'.$_.rand(1000);; $data{$_}{'id'} = rand(time); } #get random list of keys my @keys = keys %data; ################# my $h = $mw->Scrolled( 'HList', -header => 1, -columns => 2, -width => 50, -height => 60, -takefocus => 1, -background => 'steelblue', -foreground =>'snow', -selectmode => 'single', -selectforeground => 'pink', -selectbackground => 'black', # -browsecmd => \&browseThis, )->pack(-side => "left", -anchor => "n"); my $nameh = $h->header('create', 0, -text => ' Name ', -borderwidth => 3, -headerbackground => 'steelblue', -relief => 'raised'); my $idh = $h->header('create', 1, -text => ' ID ', -borderwidth => 3, -headerbackground => 'lightsteelblue', -relief => 'raised'); foreach (@keys) { my $e = $h->addchild(""); #will add at end $h->itemCreate ($e, 0, -itemtype => 'text', -text => $data{$_}{'name'}, ); $h->itemCreate($e, 1, -itemtype => 'text', -text => $data{$_}{'id'}, ); } my $button = $mw->Button(-text => 'exit', -command => sub{exit})->pack; my $buildbut = $mw->Button(-text => 'rebuild list', -command => [\&rebuild] )->pack; my $dumpbut = $mw->Button(-text => 'Dump', -command => sub{ my @entries = $h->info('children'); foreach my $entry(@entries){ print Dump([\$entry]),"\n"; } } )->pack; MainLoop; ######################################################### sub rebuild{ my @entries = $h->info('children'); foreach my $entry(@entries){ $h->delete('entry',$entry); } foreach (0..100) { $data{$_}{'name'} = 'name'.$_.rand(1000); $data{$_}{'id'} = rand(time); } #get random list of keys my @keys = keys %data; foreach (@keys) { my $e = $h->addchild(""); #will add at end $h->itemCreate ($e, 0, -itemtype => 'text', -text => $data{$_}{'name'}, ); $h->itemCreate($e, 1, -itemtype => 'text', -text => $data{$_}{'id'}, ); } $mw->update; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Auto-refreshing Perl TK HLists/Tables by zentara
in thread Auto-refreshing Perl TK HLists/Tables by GriffinP

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.