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
| 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 srfil ( id_srfil, ct, date_srfil, heure_s, evt, am, etat_am, af, msg)". " 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 ( $id_srfil, $ct, $date, $heure, $evt, $am, $etat, $af, $msg );
while (<$src>) {
if ( not $in and m/^====([\w\d]+)/ ) {
$ct = $1;
}
elsif ( not $in and my ($cmd) = (m/\s*SRFIL/) ) {
$in = 1;
}
elsif ( $in == 1 and m/^\s*TRAITEMENT ...... ACC/ ) {
$in = 2;
}
# dans le cas ou command == SRFIl
elsif ($in == 2 and m{^\s+(\d{2}\-\d{2}\-\d{2})/(\d{2})\s+\w{1}\s+(\d{2})\s+\w{2}\s+(\d{2})\s+EVT=(.*) $}x)
{
if ( defined $date ) {
$sth->execute( $id_srfil, $ct, $date, $heure, $evt, $am, $etat, $af, $msg )
or die "pb de requete : $DBI::errstr";
}
( $date, $heure, $evt, $am, $etat, $af, $msg ) = (undef) x 7;
$date = $1;
$heure = $2.':'.$3.':'.$4;
$evt = $5;
}
elsif ($in == 2
and m{^\s*/AM\s*=\s*([\w\d]+)\s*ETAT=(\w+)\s*AF\s*=\s*(.*)$}x
or m{^\s*/AM\s*=\s*([\w\d]+)\s*ETAT=(\w+)$}x)
{
$am = $1;
$etat = $2;
$af = $3;
$id_srfil = $am.'_'.$date.'_'.$heure;
}
elsif ( $in == 2 and /\/\s*(.*)$/ ) { #[\s\d]+
$msg .= " ".$1;
}
elsif ( $in == 2 and m/^\s*TRAITEMENT ...... EXC/ ) {
$in = 1;
if ( defined $date ) {
$sth->execute( $id_srfil, $ct, $date, $heure, $evt, $am, $etat, $af, $msg )
or die "pb de requete : $DBI::errstr";
}
( $date, $heure, $evt, $am, $etat, $af, $msg ) = (undef) x 7;
}
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