I humble ask for your knowledge, I still working on the same program as yesterday, I am using Perl/Tk for a frontend status monitor, now the status I get them from 3 files : "santa1.txt", "santa2.txt" y "santa3.txt". But as you can see since all that data need to be update every X seconds I like 10 seconds, but I know how to read the file I already do but how to make the program read the files every 10 seconds I dont know.
#!/usr/bin/perl -W
use strict;
use warnings;
use Tk;
use Tk::BrowseEntry;
use Cwd;
use List::Util qw(shuffle);
my $mw = MainWindow->new(
-relief => 'raised',
-bd => 2,
);
$mw->title("Asociacion de Agentes Aduanales de Matamoros --- Validacio
+n Automatica");
$mw->geometry("1024x764");
my $upframe = $mw->Frame()->pack(-fill=>'x');
my $upperframe = $mw->Frame()->pack(-fill=>'x' );
my $topframe = $mw->Frame()->pack(-fill=>'x' );
my $mainframe = $mw->Frame()->pack(-expand=>1, -fill=>'both' );
my $bottomFrame = $mw->Frame()->pack(-fill=>'x');
my $exit_b = $topframe->Button(-text=>'Exit',
-command=> sub{ exit } )->pack(-side => 'right', -padx=>20
+);
######################################################################
+##################
make_entry1($upframe, 'Status ', "santa2.txt");
make_entry($upperframe,'Banco ', "santa1.txt");
my $text1 = $topframe->Label(-text => "Archivos Por enviar")->pack(-si
+de => 'left',
-expand => 1);
my $text2 = $topframe->Label(-text => "Archivos Por Enviados")->pack(-
+side => 'left',
-expand => 1);
my $text3 = $topframe->Label(-text => "Archivos de Respuesta")->pack(-
+side => 'left',
-expand => 1);
my $text4 = $bottomFrame->Label(-text => "Noticias")->pack(-side => 't
+op',
-expand => 1);
my $box1 = Build_Listbox_One($mw);
my $box2 = Build_Listbox_Two($mw);
my $box3 = Build_Listbox_Three($mw);
my ($enviar, $enviados, $respuestas) = Start_Directory_Monitors( $mw,
+$box1, $box2, $box3 );
my $box4 = Build_Listbox_Four($mw);
Tk::MainLoop();
sub Build_Listbox_One {
my $box1 = $mainframe->Scrolled('Listbox',
-scrollbars => 'ose')
->pack( -side => 'left', -expand=>1, -fill=>'both' );
return $box1;
}
sub Build_Listbox_Two {
my $box2 = $mainframe->Scrolled('Listbox',
-scrollbars => 'ose')
->pack( -side => 'left', -expand=>1, -fill=>'both' );
return $box2;
}
sub Build_Listbox_Three {
my $box3 = $mainframe->Scrolled('Listbox',
-scrollbars => 'ose')
->pack( -side => 'left', -expand=>1, -fill=>'both' );
return $box3;
}
sub Build_Listbox_Four {
my $box4 = $bottomFrame->Scrolled('Listbox',
-scrollbars => 'ose')
->pack( -side => 'left', -expand=>1, -fill=>'both' );
my $noticias1;
open(DAT3,"santa3.txt") || die ("No se pudo abrir el arc
+hivo de Noticias");
my @noti = <DAT3>;
close(DAT3);
foreach (@noti) {
$box4->insert(0, @noti);
}
return $box4;
}
sub Start_Directory_Monitors {
my $mw = shift;
my $enviar_display = shift;
my $enviados_display = shift;
my $respuesta_display = shift;
my $repetir_display1 = shift;
my $repetir_display2 = shift;
my $enviar = $mw->repeat(5000, [ \&list_dir_enviar, $enviar_dis
+play ] );
my $env = $mw->repeat(5000, [ \&list_dir_enviados, $enviados_d
+isplay ] );
my $res = $mw->repeat(5000, [ \&list_dir_respuesta, $respuesta_
+display ] );
return $enviar, $env, $res;
}
# monitor enviados
sub list_dir_enviar {
my $box = shift;
$box->delete(0,'end'); # empty listbox
my @items = glob "c:/AAAvalida/valida/enviar/*.*";
foreach (@items) {
$box->insert('end', $_);
}
}
sub list_dir_enviados {
my $box1 = shift;
$box1->delete(0,'end'); # empty listbox
my @items = glob "c:/AAAvalida/valida/enviados/*.*";
foreach (@items) {
$box1->insert('end', $_);
}
}
sub list_dir_respuesta {
my $box2 = shift;
$box2->delete(0,'end'); # empty listbox
my @items = glob "c:/AAAvalida/valida/respuestas/*.*";
foreach (@items) {
$box2->insert('end', $_);
}
}
sub make_entry {
my ($upperframe,$label,$filename) = @_;
my $label_info3 = $upperframe->Label(
-text => 'Bancos :',
)->pack(-side => 'left',
-expand => 1);
open(DAT, $filename) || die("Could not open file!");
my @stat=<DAT>;
close(DAT);
foreach my $stat(@stat)
{
chomp ($stat);
my $banco;
my $stado;
($banco,$stado)=split(/\|/,$stat);
my $label_display = $upperframe->Label(
-textvariable => \$banco
)->pack(-side => 'left',
-expand => 1);
if ($stado eq "ACTIVO"){
my $entry_info = $upperframe->Entry(
-foreground => 'blue',
-textvariable => \$stado,
-width => 20,
)->pack(-side => 'left',
-expand => 1);
} else {
my $entry_info = $upperframe->Entry(
-foreground => 'red',
-textvariable => \$stado,
-width => 20,
)->pack(-side => 'left',
-expand => 1);
}
}
}
sub make_entry1 {
my ($upframe,$labe2,$filename1) = @_;
my $label_info4 = $upframe->Label(
-text => 'Status :',
)->pack(-side => 'left',
-expand => 1);
open(DAT1, $filename1) || die("Could not open file!");
my @stat1=<DAT1>;
close(DAT1);
foreach my $stat1(@stat1)
{
chomp ($stat1);
my $operacion;
my $stado1;
($operacion,$stado1)=split(/\|/,$stat1);
my $label_display1 = $upframe->Label(
-textvariable => \$operacion
)->pack(-side => 'left',
-expand => 1);
if ($stado1 eq "ACTIVO"){
my $entry_info1 = $upframe->Entry(
-foreground => 'blue',
-textvariable => \$stado1,
-width => 20,
)->pack(-side => 'left',
-expand => 1);
} else {
my $entry_info1 = $upframe->Entry(
-foreground => 'red',
-textvariable => \$stado1,
-width => 20,
)->pack(-side => 'left',
-expand => 1);
}
}
}