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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #!/usr/bin/perl
# ------------------------------------------------------------------------------------
# Ce programme doit decompte le nombre de ligne de 2 fichiers et les comparer
# ------------------------------------------------------------------------------------
# Argument d'entree
# $ARGV[0] : Chemin sur environement T
# $ARGV[1] : Chemin sur environement D
# ------------------------------------------------------------------------------------
# Argument de Sortie
# Fichier log format Speudo csv avec entete
# "Nomfichier1;Nombre d'enregistrement F1;Nomfichier2;Nombre d'enregistrement F2;Test de coherence";
# ------------------------------------------------------------------------------------
#
# version 1.0 2016-03-22 ESE
# ------------------------------------------------------------------------------------
use strict; # controle
use warnings;
use Data::Dumper;
#strict et warnings : sont deux modules internes a Perl permettant de verifier la syntaxe de votre code et de vous alerter a la compilation du programme ;
require "./Fonctions/FonctionFichiers.pl";
# ------------------------------------------------------------------------------------
# fonctions internes
# ------------------------------------------------------------------------------------
sub hashfichier {
my %retourne_hash = shift; # table de hash
my $extention = "";
my $line_nbr = 0;
my $taillefic = 0;
my $repert = "";
my $nomdufichier;
my $horodate = "";
my @deffic;
my @T_fic = $_[1];
foreach my $name (@T_fic) {
#debug mode
# print "$name\n";
$line_nbr = compteurdeligne_fichier($name);
$taillefic = -s $name;
@deffic = Nomfic($name);
$repert = $deffic[1];
$nomdufichier = $deffic[0];
$horodate = substr( $repert, 0, 14 );
if ( $nomdufichier =~ m/.err/ ) {
$extention = '.err';
}
elsif ( $nomdufichier =~ m/.dat/ ) {
$extention = '.dat';
}
else {
$extention = 'autre';
}
$retourne_hash{$nomdufichier} = {
Vacation => $name,
Taille => $taillefic,
NBRLigne => $line_nbr,
Rep => $repert,
HoroD => $horodate,
Ext => $extention,
top => "faux"
};
}
return \%retourne_hash; # renvoi d'une reference au hachage
}
# variable global
my $fichier_1 = $ARGV[0];
my $fichier_2 = $ARGV[1];
my @T_fic1 = undef;
my @T_fic2 = undef;
my $nmfic_1;
my $header_fic_log = "";
# debut code
# doit contenir : nom du fichier + longueur.
# print " $ARGV[0] \n";
# print " $ARGV[1] \n";
# liste les fichiers *.dat des repertoire
# print "Appel aux fonctions \n";
@T_fic1 = listedesfichiers( $ARGV[0], "*.dat" );
push( @T_fic1, listedesfichiers( $ARGV[0], "*.err" ) );
@T_fic2 = listedesfichiers( $ARGV[1], "*.dat" );
push( @T_fic2, listedesfichiers( $ARGV[1], "*.err" ) );
######################
# MAIN #
######################
#debug mode
# print ("@T_fic1 \n ");
# print ("@T_fic2 \n ");
# definir le nom du fichier log
my $valeur = "/";
my @T_FIC = split( /${valeur}/, $ARGV[0] );
my $nomficlog = $T_FIC[$#T_FIC];
$nomficlog = "../Logs/${nomficlog}.log"; # Fichier de log
open( my $fichierlog, '+>', $nomficlog ) or die("open: $!");
print( $fichierlog "Information des actions de ${nomficlog} \n \n" );
my $nbfic1 = $#T_fic1 + 1; # compte le nombre de fichier
print( $fichierlog " Nombre des fichiers .dat .err : $nbfic1 \n" );
print ("avant \n");
my %files_hash_1;
my %files_hash_2;
my %P_files_hash_1 = hashfichier( \%files_hash_1, @T_fic1 );
my %P_files_hash_2 = hashfichier( \%files_hash_2, @T_fic2 );
print Dumper \%P_files_hash_1;
print Dumper \%P_files_hash_2;
print "fin";
# traitement 2 pass
@T_FIC = split( /${valeur}/, $ARGV[1] );
$nomficlog = $T_FIC[$#T_FIC];
$nomficlog = "${nomficlog}.log";
print( $fichierlog "\n \n Comparaison avec ${nomficlog} \n " );
my $nbfic2 = $#T_fic2 + 1; # compte le nombre de fichier
close($fichierlog);
exit; |
Partager