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
| #!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $basedir = 'C:/Program Files/EasyPHP1-8/www/traitement';
open my ($src), '<', "$basedir/ctrlsys_6hCB01_14.txt"
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 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 = $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*([\w\d]+)
$}x
)
{
$am = $1;
$etat = $2;
$af = $3;
$id_srfil = $ct.'_'.$am.'_'.$heure;
}
elsif ( $in == 2 and /\/\s*([\s\d]+)$/ ) {
my $msg .= $1;
}
elsif ( $in == 2 and m/^\s*TRAITEMENT ...... EXC/ ) {
if ( defined $date ) {
$sth->execute( $id_srfil, $ct, $date, $heure, $evt, $am, $etat, $af, $msg )
or die "pb de requete : $DBI::errstr";
}
( $id_srfil, $ct, $date, $heure, $evt, $am, $etat, $af, $msg ) = (undef) x 8;
$in = 1;
}
elsif ( $in == 1 and m/^\s*EXC\s*$/ ) {
$in = 0;
}
}
close $src;
$dbh->disconnect; |