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
| #!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $basedir = 'C:/Program Files/EasyPHP1-8/www/traitement';
open my ($src), '<', "$basedir/AUDIT_CIC_HS16.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 mic_hs ( ct, afct, etat, nmfsc, cic, natc, tyc, ps, tyr)"
. " 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 ( $ct, $afct, $etat, $nmfsc, $cic, $natc, $tyc, $ps, $tyr);
while (<$src>) {
if ( not $in and my ($cmd) = (m/====\s*CT=(\w{2}\d{2})\s*====/) ) {
$ct = $1;
$in = 1;
}
elsif (
$in == 1
and m{^\s*
AFCT\s*=\s*(\d{3}\-\d{3}\-\d{2})
\s*ETAT\s*=\s*(\w{4}\+\w{4})
$/}x
)
{
if ( defined $afct ) {
$sth->execute( $ct, $afct, $etat, $nmfsc, $cic, $natc, $tyc, $ps, $tyr)
or die "pb de requete : $DBI::errstr";
}
$afct = $1;
$etat = $2;
}
elsif (
$in == 1
and m{^\s*
NATC\s*=\s*(\w{3}\d{1})
\s*TYC\s*=\s*(\w{3}\d{2}\w{1}\d{2})
\s*NFSC\s*=\s*(.*)
$/}x
)
{
$natc = $1;
$tyc = $2;
$nmfsc = $3;
}
elsif ( $in == 1 and m{^\s*
PS\s*=(\d{5})
\s*CIC=(\d{5})
\s*TYR=(\w{2})
$/}x) {
$ps = $1;
$cic = $2;
$tyr = $3;
if ( defined $afct ) {
$sth->execute( $ct, $afct, $etat, $nmfsc, $cic, $natc, $tyc, $ps, $tyr)
or die "pb de requete : $DBI::errstr";
}
( $ct, $afct, $etat, $nmfsc, $cic, $natc, $tyc, $ps, $tyr) = (undef) x 9;
$in = 1;
#elsif ( $in == 1 and eof ) { $in = 0; }
}
}
close $src;
$dbh->disconnect; |
Partager