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 102 103 104 105 106 107 108 109 110
|
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(
"INSERT INTO glril (date, heure, ct,nbeq, nbeqpt, date_intr, afgrx, glrx, brcx, etat, tr, brcxb, etatb)"
. " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
# 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 ($date, $heure, $ct,$nbeq, $nbeqpt,$afgrx, $glrx, $brcx, $etat, $tr, $brcxb, $etatb);
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 m/^====([\w\d]+)/ ) {
$ct = $1;
}
elsif ( not $in and my ($cmd) = (m/\s*GLRIL/) ) {
$in = 1;
}
elsif ($in == 1
and m{^\s+CEN=([\w\d]+)/(\d{2}\-\d{2}\-\d{2})/(\d{2})\s+\w{1}\s+(\d{2})\s+\w{2}\s+(\d{2})/(.*)}x
)
{
$date = $2;
$heure = $3.':'.$4.':'.$5;
}
elsif ( $in == 1 and m/^\s*TRAITEMENT ...... ACC/ ) {
$in = 2;
}
elsif (
$in == 2
and m{^\s+AFGRX=(\d{3}\-\d{2})\s+GLRX=([\w\d]+)\s+BRCX=([\w\d]+)\s+ETAT=([\w\d]+)\s+BRCX=([\w\d]+)\s+ETAT=([\w\d]+)\s+TR=([\w\d]+)}x
)
{
$afgrx = $1;
$glrx = $2;
$brcx = $3;
$etat = $4;
$brcxb = $5;
$etatb = $6;
$tr = $7;
}
elsif (
$in == 2
and m{^\s+AFGRX=(\d{3}\-\d{2})\s+GLRX=([\w\d]+)\s+BRCX=([\w\d]+)\s+ETAT=([\w\d]+)\s+TR=([\w\d]+)}x
)
{
$afgrx = $1;
$glrx = $2;
$brcx = $3;
$etat = $4;
$tr = $5;
}
elsif ( $in == 2
and m{^\s+NBEQ\s+=\s+([\w\d]+)}x
)
{
$nbeq = $1;
}
elsif (
$in == 2
and m{^\s+NBEQPT\s+=\s+([\w\d]+)}x
)
{
$nbeqpt = $1;
if ( defined $nbeq ) {
$sth->execute($date, $heure, $ct, $nbeq, $nbeqpt, $dateUs, $afgrx, $glrx, $brcx, $etat, $tr, $brcxb, $etatb)
or die "pb de requete : $DBI::errstr";
}
($date, $heure, $nbeq, $nbeqpt, $afgrx, $glrx, $brcx, $etat, $tr, $brcxb, $etatb) = (undef) x 10;
}
elsif ( $in == 2 and m/^\s*TRAITEMENT ...... EXC/ ) {
$in = 1;
}
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