padawan_linuxero has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use warnings; use strict; use Tk; my @banklist = qw(Banamex HSBC Santander Banorte); my $mw = MainWindow->new(); my %data; foreach my $bank (@banklist) { $data{$bank}{'frame'} = $mw->Frame->pack(-fill=>'x'); $data{$bank}{'bankname'} = $bank; $data{$bank}{'status'} = 'offline'; $data{$bank}{'label'} = $data{$bank}{'frame'}->Label( -textvariable => \$data{$bank}{'bankname'})->pack(-side=>'left'); $data{$bank}{'entry'} = $data{$bank}{'frame'}->Entry( -textvariable => \$data{$bank}{'status'}, -bg => 'white', )->pack(-side=>'right'); } $mw->repeat(10000, \&CheckForActiveBanks); sub CheckForActiveBanks { my %statusList = (); #-- Reset the list of bank statuses. # foreach my $bank (@banklist) { $statusList{$bank} = 'X'; } #-- Read in the data file. # open (DAT, "santa1.txt") || die ("No se pudo abrir el archivo"); my @lines = <DAT>; close(DAT); #-- Set the status for each bank found in the data file. # foreach my $lineas (@lines) { chomp $lineas; my $statuss; my $banco; ($banco, $statuss) = split(/\|/, $lineas); $statusList{$banco} = $statuss; } #-- Update the data for the list of banks. # foreach my $bank (@banklist) { if ($statusList{$bank} eq "ACTIVO") { $data{$bank}{'entry'}->configure(-fg => 'green'); $data{$bank}{'status'} = 'online'; } else { $data{$bank}{'entry'}->configure(-fg => 'red'); $data{$bank}{'status'} = 'offline'; } } } MainLoop;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem with hash
by kyle (Abbot) on Jun 03, 2008 at 16:37 UTC | |
by padawan_linuxero (Scribe) on Jun 03, 2008 at 17:30 UTC | |
by wade (Pilgrim) on Jun 03, 2008 at 17:33 UTC | |
Re: Problem with hash
by wade (Pilgrim) on Jun 03, 2008 at 16:41 UTC | |
by wade (Pilgrim) on Jun 03, 2008 at 16:49 UTC | |
Re: Problem with hash
by starbolin (Hermit) on Jun 03, 2008 at 16:58 UTC | |
Re: Problem with hash
by apl (Monsignor) on Jun 03, 2008 at 16:55 UTC |