Hi
To explain you better, I am copy/pasting the entire snippet run on a small input file (info.txt). The info.txt content is following :

location usa age 22 phone 201
alex
location germany age 22 phone 202
alex
location france age 23 phone 101
martin

Above info.txt is having 3 sets of data (2 for alex and 1 for martin). To test the application , you have to first keep only one set of data for alex only, then you replace the file by the above one to see the "Entry '1' not found Error"

One apology, the regular expression is working fine for me. If it does not work for you, please correct it. I have kept the file content as simple as possible. Pardon me please on this.
One more thing is, I have kept an entry box above to let the user to set the frequency of refreshing the gui. How can I put that Entry box textvariable to the repeat function so that it picks it up. Default should be 5000.

Following is the code

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; #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)->pa +ck(-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); open_report(); my $timer1 = $mw->repeat(5000, \&clear_data); MainLoop; sub clear_data{ print "Inside clear data \n"; read_file(); my $path = 0; for my $locationkey (sort keys %{$hash->{$user}}){ _refreshData($path,$locationkey); $path++; } } sub _refreshData { my $path = shift; my $location = shift; print "Inside refreshdata $path | $location \n"; my $availbl = $hash->{$user}->{$location}->{age}; my $chk = $hash->{$user}->{$location}->{phone}; if($hl->itemExists($path,0)){ #if($hl->info(exists, $path)){ print "itemexists ...\n"; $hl->itemConfigure($path,0,-text=> $hash->{$user}->{$location}->{l +ocation}); $hl->itemConfigure($path,1,-text=> $hash->{$user}->{$location}->{a +ge}) ; $hl->itemConfigure($path,2,-text=> $hash->{$user}->{$location}->{p +hone}); } else { print "Inside else ....\n"; $hl->add($path); $hl->itemCreate($path,0,-text=> $hash->{$user}->{$location}->{loca +tion}); $hl->itemCreate($path,1,-text=> $hash->{$user}->{$location}->{age} +) ; $hl->itemCreate($path,2,-text=> $hash->{$user}->{$location}->{phon +e}); } } sub read_file { print "Inside read file \n"; open(FP, "< info.txt"); while(<FP>){ if(/location (\w+) age (\d+) phone (\d+)/){ ($location,$age,$use) = ($1,$2,$3); print "$1 $2 $3\n"; } if (/^$user\s*/){ $hash->{$user}->{$location}->{location} = $location; $hash->{$user}->{$location}->{age} = $age; $hash->{$user}->{$location}->{phone} = $use; } } close(FP); } sub open_report{ read_file(); my $path = 0; for my $locationkey (sort keys %{$hash->{$user}}){ _insertData($path,$locationkey); $path++; } } sub _insertData { print "Inside insertdata\n"; my $path = shift; my $location = shift; print "Inside insertdata $path | $location \n"; $hl->add($path); $hl->itemCreate($path,0,-text=> $hash->{$user}->{$location}->{loca +tion}); $hl->itemCreate($path,1,-text=> $hash->{$user}->{$location}->{age} +) ; $hl->itemCreate($path,2,-text=> $hash->{$user}->{$location}->{phon +e}); }

In reply to Re^6: Perl Tk , MainLoop, destroy function problem by ghosh123
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.