1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
use strict;
use warnings;
use DBI;
my $pDirectory;
my $path = "C:/Program Files/EasyPHP1-8/www/traitement/sources";
opendir ($pDirectory,$path)
or die ("Directory ".$path." can't be open!\n");
my @Directory_list = readdir($pDirectory);
closedir ($pDirectory);
foreach my $File (@Directory_list)
{
if( $File =~ m/\.txt$/ )
{
#.....VOILA MON CODE POUR TRAITER TOUS LES FICHIERS DE LA LISTE.............................
open my ($src), '<', "$path/$File" or die "E/S : $!\n";
# Connect to the database.
my $dbh = DBI->connect( "DBI:mysql:database=tdm;host=localhost",
"chakri", "farid", { 'RaiseError' => 1 } );
my $sth =
$dbh->prepare(
"update alarme set seuil='$seuil' and pri='$pri' where texal='REGULATION ALARMES/I' and nidal='$nidal'" );
# variable d'état pour savoir si l'on se trouve dans ule paragraphe qu'on veut imprimer ($in == 2), après une commande ($in == 1),
# ou en dehors de tout cela ($in == 0)
my $in = 0;
my ( $ct, $inf1, $id_alamre, $date_al, $heure, $nidal, $texal, $typ, $cat, $seuil, $pri);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $dateUs = (1900+$year)."-".($mon+1)."-".$mday;
while (<$src>) {
if ( not $in and my ($cmd) = (m/\s*ALAIL/) ) {
$in = 1;
}
elsif ( $in == 1 and m/^\s*TRAITEMENT ...... ACC/ ) {
$in = 2;
}
elsif (
$in == 2
and m{^\!+\s+\*([\w\d]+)\/(\d{3})\s+\/(\d{2}\-\d{2}\-\d{2})\/(\d{2})\s+\w{1}\s+(\d{2})\/N=(\d{4})\/TYP=(\w{3})\/CAT=(\w{2})\/EVENT=(.*)$}x
)
{
$date_al = $3;
$heure = $4.':'.$5;
$nidal = $6;
$typ = $7;
$cat = $8;
}
elsif (
$in == 2
and m{^\s*\/NCEN=([\w\d]+)\s+\/(.*)$}x
)
{
$ct = $1;
$inf1 = $2;
}
elsif ( $in == 2 and m{^\s*\/TEXAL=(.*)$}x ) { #[\s\d]+
$texal = $1;
}
elsif ( $in == 2 and m{^\s+\/SEUIL=([\w\d]+)\s+\/PRI=([\w\d]+)$}x ) { #[\s\d]+
$seuil = $1;
$pri = $2;
$id_alamre = $ct.'_'.$dateUs.'_'.$nidal;
if ( defined $pri ) {
$sth->execute($ct, $inf1, $id_alamre, $date_al, $heure, $nidal, $texal, $typ, $cat, $dateUs, $seuil, $pri)
or die "pb de requete : $DBI::errstr";
}
($ct, $inf1, $id_alamre, $date_al, $heure, $nidal, $texal, $typ, $cat) = (undef) x 9;
}
elsif ( $in == 2 and m/^\s*TRAITEMENT ...... EXC/ ) {
$in = 1;
if ( defined $pri ) {
$sth->execute($ct, $inf1, $id_alamre, $date_al, $heure, $nidal, $texal, $typ, $cat, $dateUs, $seuil, $pri)
or die "pb de requete : $DBI::errstr";
}
($ct, $inf1, $id_alamre, $date_al, $heure, $nidal, $texal, $typ, $cat) = (undef) x 9;
}
elsif ( $in == 1 and m/^\s*EXC\s*$/ ) {
$in = 0;
}
}
close $src;
$dbh->disconnect;
#.....VOILA LA FIN DE MON CODE POUR TRAITER TOUS LES FICHIERS DE LA LISTE.............................
}
} |
Partager