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 nssin ( ct, tmp_arch, tmp_act, ap_pr_ar, ap_pr_act, ap_rl_ar, ap_rl_act, ap_cp_ar, ap_cp_act)"
. " 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, $tmp_arch, $tmp_act, $ap_pr_ar, $ap_pr_act, $ap_rl_ar, $ap_rl_act, $ap_cp_ar, $ap_cp_act);
while (<$src>) {
if ( not $in and my ($cmd) = (m/\s*NSSIN/) ) {
$in = 1;
}
elsif ( $in == 1 and m/^\s*TRAITEMENT ..... ACC/ ) {
$in = 2;
if ( defined $ct) {
$sth->execute( $ct, $tmp_arch, $tmp_act, $ap_pr_ar, $ap_pr_act, $ap_rl_ar, $ap_rl_act, $ap_cp_ar, $ap_cp_act )
or die "pb de requete : $DBI::errstr";
}
( $ct, $tmp_arch, $tmp_act, $ap_pr_ar, $ap_pr_act, $ap_rl_ar, $ap_rl_act, $ap_cp_ar, $ap_cp_act) = (undef) x 9;
}
# dans le cas ou command == NSSIN
elsif ($in == 2 and m{^\s+\*\s+NCEN=([\w\d]+)\s+\!\s+(\d{2}\-\d{2}\-\d{2}\/\d{2}\-\d{2})\s+\!\s+(\d{2}\-\d{2}\-\d{2}\/\d{2}\-\d{2})\s+\*$}x)
{
$ct = $1;
$tmp_arch = $2;
$tmp_act = $3;
}
elsif ($in == 2 and m{^\s+\*\s+APP.PRESENTES\s+\!\s+([\w\d]+)\s+\!\s+([\w\d]+)\s+\*$}x )
{
$ap_pr_ar = $1;
$ap_pr_act = $2;
}
elsif ($in == 2 and m{^\s+\*\s+APP.RELACHES\s+\!\s+([\w\d]+)\s+\!\s+([\w\d]+)\s+\*$}x )
{
$ap_rl_ar = $1;
$ap_rl_act = $2;
}
elsif ($in == 2 and m{^\s+\*\s+APP.COUPES\s+\!\s+([\w\d]+)\s+\!\s+([\w\d]+)\s+\*$}x )
{
$ap_cp_ar = $1;
$ap_cp_act = $2;
}
elsif ( $in == 2 and m/^\s*TRAITEMENT ..... EXC/ ) {
$in = 1;
if ( defined $ct) {
$sth->execute( $ct, $tmp_arch, $tmp_act, $ap_pr_ar, $ap_pr_act, $ap_rl_ar, $ap_rl_act, $ap_cp_ar, $ap_cp_act )
or die "pb de requete : $DBI::errstr";
}
( $ct, $tmp_arch, $tmp_act, $ap_pr_ar, $ap_pr_act, $ap_rl_ar, $ap_rl_act, $ap_cp_ar, $ap_cp_act) = (undef) x 9;
}
elsif ( $in == 1 and m/^\s*EXC\s*$/ ) {
$in = 0;
}
}
close $src;
$dbh->disconnect; |
Partager