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
| use strict;
use warnings;
use DBI;
my $pDirectory;
my $path = "C:/Program Files/EasyPHP1-8/www/traitement/trtaxe10";
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 rp ( ct, rp, etat, twin, etatt, date_intr, ds, maint)"
. " 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, $rp, $etat, $twin, $etatt, $ds, $maint);
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/^AXE\s+([\w\d]+)/ ) {
$ct = $1;
}
if ( not $in and my ($cmd) = (m/\s*Etat des RP/) ) {
$in = 1;
}
elsif ($in == 1 and m{^\s+([\d\-]+)\s+([\w\-]+)\s+([\w\d\-]+)\s+([\d\-]+)\s+([\w\-]+)\s+([\d\-]+)\s+([\w\d\-]+)$}x)
{
$rp = $1;
$etat = $2;
$twin = $3;
$etatt = $5;
$ds = $6;
$maint = $7;
if ( defined $rp ) {
$sth->execute($ct, $rp, $etat, $twin, $etatt, $ds, $maint, $dateUs )
or die "pb de requete : $DBI::errstr";
}
($ct, $rp, $etat, $twin, $etatt, $ds, $maint, $dateUs ) = (undef) x 8;
}
close $src;
$dbh->disconnect;
}
}
} |
Partager