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
|
use strict;
my ($fichTIA, $fichCOPtf) = ("TIA061010.ELI","COPtf.txt");
#my ($fichTIA, $fichCOPtf) = ("DataTIA.ELI","COPtfSmall.txt");
my ($centre,$old_centre);
my ($ptf, $old_ptf);
my ($ptfData, $old_ptfData);
my ($isFileCentreOpened);
my ($firstPtf) = ("true");
my @tabData;
my @tabDataProduit;
my @cleProduit;
my @old_cleProduit;
$, = "\t";
$\ = "";
open(FILE_PtfCentre, "<$fichCOPtf") || die "File $fichCOPtf Erreur E/S : $!\n";
open(FILE_DATA, "<$fichTIA") || die "File $fichTIA Erreur E/S : $!\n";
while (<FILE_PtfCentre>) {
my @tab = split(';',$_);
$centre = $tab[1];
$ptf = $tab[2];
$centre =~ s/\s+$//; #right trim
$ptf =~ s/\s+$//; #right trim
#print "$centre,$ptf.\n";
# Change de fichier centre a chaque nouveau centre
if($centre ne $old_centre) {
if( FILE_OUT_CENTRE) {
close FILE_OUT_CENTRE;
}
#open(FILE_OUT_CENTRE, ">Out/CO_$centre.txt") || die "File Out/CO_$centre.txt Erreur E/S : $!\n";
open(FILE_OUT_CENTRE, ">OutProduit/produits.txt") || die "File OutProduit/peoduits.txt Erreur E/S : $!\n";
}
# Peuple le portefeuille courant
#if(@tabData){
if(@tabDataProduit){
$ptfData = $tabData[3];
$tabData[2] = $centre;
$tabData[3] = $ptf;
#on découpe le produit qui est à partir du 12éme élément
@tabDataProduit=split(";",$tabData[12]);
if(!($old_cleProduit[0] eq $cleProduit[0]&&$old_cleProduit[1] eq $old_cleProduit[1]&&$old_cleProduit[2] eq $old_cleProduit[2] && $old_cleProduit[3] eq $old_cleProduit[3])){
print FILE_OUT_CENTRE $tabDataProduit[0],";",$tabDataProduit[3],";",$tabDataProduit[4],";",$tabDataProduit[5],";",$tabDataProduit[1],";",$tabDataProduit[19],";",$tabDataProduit[2],";",$tabDataProduit[16],";","\n";
}
$old_ptfData = $ptfData;
#assignation des anciennes valeurs de la clé
$old_cleProduit[0]=$cleProduit[0];
$old_cleProduit[1]=$cleProduit[3];
$old_cleProduit[2]=$cleProduit[4];
$old_cleProduit[3]=$cleProduit[5];
}
BOUCLE: while ("true") {
while (<FILE_DATA>) {
# @tabData = split("\t",$_);
@tabData = split("\t",$_);
$ptfData = $tabData[3];
if(!$firstPtf) {
last BOUCLE if $ptfData ne $old_ptfData;
} else {
$firstPtf = ""; #false
}
$tabData[2] = $centre;
$tabData[3] = $ptf;
#on découpe le produit qui est à partir su 12éme élémzent
@tabDataProduit=split(";",$tabData[12]);
$cleProduit[0]=$tabDataProduit[0];
$cleProduit[1]=$tabDataProduit[3];
$cleProduit[2]=$tabDataProduit[4];
$cleProduit[3]=$tabDataProduit[5];
if(!($old_cleProduit[0] eq $cleProduit[0]&&$old_cleProduit[1] eq $old_cleProduit[1]&&$old_cleProduit[2] eq $old_cleProduit[2] && $old_cleProduit[3] eq $old_cleProduit[3])){
print FILE_OUT_CENTRE $tabDataProduit[0],";",$tabDataProduit[3],";",$tabDataProduit[4],";",$tabDataProduit[5],";",$tabDataProduit[1],";",$tabDataProduit[19],";",$tabDataProduit[2],";",$tabDataProduit[16],";","\n";
}
$old_ptfData = $ptfData;
#assignation des anciennes valeurs de la clé
$old_cleProduit[0]=$cleProduit[0];
$old_cleProduit[1]=$cleProduit[3];
$old_cleProduit[2]=$cleProduit[4];
$old_cleProduit[3]=$cleProduit[5];
}
# On est a la fin de FILE_DATA il faut reprendre au début
close FILE_DATA;
open(FILE_DATA, "<$fichTIA") || die "Erreur E/S : $!\n";
}
$old_ptf = $ptf;
$old_centre = $centre;
}
close FILE_OUT_CENTRE;
close FILE_PtfCentre;
close FILE_DATA; |
Partager