Hi again, I realize you are a beginner at this gui business, so in lieu of trying to solve your logic problem with the code as you have written it, I would like to suggest to you an alternative program flow structure, which would be cleaner.

You don't need 5 subs to do the refresh, where you have clear_data(), _refreshdata(), read_file(), open_report(), and finally _insertData().

You can more easily do it in one sub called refresh(), which is called by the timer. Now in my code flow, refresh() will read the file, then just insert the data in its appropriate $path. You will need a few tests in there, requiring that if the $path already exists, you will reconfigure that path; and if the path dosn't exist, then an addpath is used. It should all be done in 1 sub for maintaining easy flow.

Also 1 final point, you don't distinquish between users in the rows. You data seems to have multiple users, and I would have the user as the data in the first column, where you put it in a label above the Hlist. But it's your code, and you know what needs to be done.

#!/usr/bin/perl use Tk; use Tk::HList; use Tk::ItemStyle; use Data::Dumper; my $user = $ARGV[0] || 'alex'; my $hash = {}; my ($location,$age,$use,$vendor,$feature); my $sec = 5000; #default value #gui variables my ($hl,$ok,$alert); # Making the Gui my $mw = new MainWindow; $mw->geometry("500x200"); my $userframe = $mw->Frame(-width=>5,-height=>10)->pack(-side=>'top',- anchor=>'nw'); $userframe->Label(-text => "USER: $user")->pack(-side => 'left', -anch +or => 'nw',-padx => 0); $userframe->Label(-text => "Set time")->pack(-side => 'left',-anchor = +> 'w',-padx => 0); my $frequency = $userframe->Entry(-width=>5,-textvariable=> \$sec) ->pack(-side => 'left',-anchor => 'nw',-padx => 0); my $hlistframe = $mw->Frame()->pack(-fill => 'both', -expand => 1); $hl = $hlistframe->Scrolled('HList', -scrollbars => 'ose', -columns =>4 , -header => 1, -width => 100, -command => sub {print "AAA\n";}, -selectmode => 'browse', )->pack(-fill => 'both',-expand =>1 ); my $label1 = $hl->Label(-text => "location", -anchor => 'w'); $hl->headerCreate(0,-itemtype => 'window',-widget => $label1); my $label3 = $hl->Label(-text => "Age", -anchor => 'w'); $hl->headerCreate(1,-itemtype => 'window',-widget => $label3); my $label4 = $hl->Label(-text => "phone", -anchor => 'w'); $hl->headerCreate(2,-itemtype => 'window',-widget => $label4); refresh(); # called to start the first refresh # the timer is now at the end of the refresh() sub MainLoop; sub refresh { # 1 here you read the file # 2 do your regexes # 3 test to see how many paths you have thru info('children') # 4 reconfigure the existing paths with new data # 5 if new paths are needed add them, if you have too many # existing paths, hide them # finally call it again later # make a lower bound for timer # in case your user sets $sec to 0 if( $sec < 1000){ $sec = 1000 } $mw->after( $sec, \&refresh); }

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

In reply to Re: Perl Tk , MainLoop, destroy function problem by zentara
in thread Perl Tk , MainLoop, destroy function problem by ghosh123

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.