#!/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;
In reply to Problem with hash by padawan_linuxero
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |