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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#MAIN
my $refH=extractPathSol("XML_Depart.xml");
my %hashPathSol=%$refH;
print "LISTE HASH:\n";
foreach my $key (sort keys(%hashPathSol)){
print "CLE: ".$key."\tVALEUR: ".$hashPathSol{$key}."\n";
}
#FUNCTIONS
sub is_array {
my ($var) = @_;
return ( ref($var) eq 'ARRAY' );
}
sub function_psl{
my ($refArgPSL, $refCode, $refHash)=@_;
print "function_psl\n";
if(!$refArgPSL->{'psl'}){
function_duinv($refArgPSL, $refHash);
return 0;
}
my $code=$$refCode;
my $pslcode="";
if(is_array($refArgPSL->{'psl'})){
print "PSL ARRAY\n";
foreach my $elt ($refArgPSL->{'psl'}){
#recuperer le pslcode s il existe
print "Elt:".join(" ", $elt)."\n";
if(is_array($elt)){
my @tableauElt=$elt;
foreach my $tabElt (@tableauElt){
print "tabElt =".$tabElt."\n";
if(is_array($tabElt)){
foreach my $ee ($tabElt){
print "Array $ee\n";
function_psl($ee, \$code, $refHash);
}
next;
}
if($tabElt->{'pslcode'}){
$pslcode .= "-".$tabElt->{'pslcode'};
print "=> pslcode array=".$pslcode."\n";
}
$code.= "-".$pslcode;
print "\t+++ CODE=".$pslcode."\n";
function_psl($elt->{'psl'}, \$code, $refHash);
}
}
else{
if($elt->{'pslcode'}){
$pslcode .= "-".$elt->{'pslcode'};
print "=> pslcode array=".$pslcode."\n";
}
$code.= "-".$pslcode;
print "\t+++ CODE=".$pslcode."\n";
function_psl($elt->{'psl'}, \$code, $refHash);
}
}
return 1;
}
else{
print "\tPSL not ARRAY\n";
if($refArgPSL->{'psl'}->{'pslcode'}){
$pslcode = $refArgPSL->{'psl'}->{'pslcode'};
print "=> pslcode=".$pslcode."\n";
}
$code.= "-".$pslcode;
print "\t+++ CODE=".$code."\n";
function_psl($refArgPSL->{'psl'}, \$code, $refHash); #encore 1 psl en dessous
$refCode=\$code; #retourner la ref du code modifie
return 1;
}
}
sub function_duinv{
my ($refArgPSL, $refHash)=@_;
my %hashSol=%$refHash;
print "function_duinv\n";
if(!$refArgPSL->{'group'} and !$refArgPSL->{'du-inv'}){
return 0;
}
if($refArgPSL->{'group'}){
function_duinv($refArgPSL->{'group'}, $refHash);
return 1;
}
if(is_array($refArgPSL->{'du-inv'})){
print "INV ARRAY - plusieurs du-sol\n";
foreach my $elt ($refArgPSL->{'du-inv'}){
my ($codeInv, $titleInv);
if($elt->{'code'}){
$codeInv = $elt->{'code'};
print "=> codeInv=".$codeInv."\n";
}
if($elt->{'title'}){
$titleInv = $elt->{'title'};
print "=> titleInv=".$titleInv."\n";
}
my $numSol=function_dusol($refArgPSL->{'du-sol'}); #encore 1 psl en dessous
if($numSol != 0 and $numSol != -1){
#enregistrer ce numéro de solution
$hashSol{$numSol} = $titleInv.",".$codeInv;
}
}
return 1;
}
else{
print "\tINV not ARRAY - 1 seul du-sol\n";
my ($codeInv, $titleInv);
if($refArgPSL->{'du-inv'}->{'code'}){
$codeInv = $refArgPSL->{'du-inv'}->{'code'};
print "=> codeInv=".$codeInv."\n";
}
if($refArgPSL->{'du-inv'}->{'title'}){
$titleInv = $refArgPSL->{'du-inv'}->{'title'};
print "=> titleInv=".$titleInv."\n";
}
my $numSol=function_dusol($refArgPSL->{'du-sol'}); #encore 1 psl en dessous
if($numSol != 0 and $numSol != -1){
#enregistrer ce numéro de solution
$hashSol{$numSol} = $titleInv.",".$codeInv;
}
return 1;
}
}
sub function_dusol{
my ($refArgPSL, $refCode)=@_;
print "function_dusol\n";
if($refArgPSL->{'du-sol'}){
if($refArgPSL->{'du-sol'}->{'code'}){
return $refArgPSL->{'du-sol'}->{'code'};
}
print "\nIMPOSSIBLE: DU INV ".$refArgPSL->{'du-sol'}->{'code'}." sans DU SOL...\n";
return -1;
}
else{
print "\nPAS DE DU SOL \n";
return 0;
}
}
sub extractPathSol{
my ($ficName) = @_;
#créer une map avec le titre et les noms des fichiers
my %hashSol;
my ($key, $value) = ("","");
# create object
my $xml = new XML::Simple (KeyAttr=>[]);
# read XML file
my $data = $xml->XMLin($ficName);
#open ECRIRE, ">dumper.txt" or die ("Erreur lors de la creation de dumper.txt");
#print ECRIRE Dumper($data);
#close ECRIRE;
my $code="";
if(function_psl($data, \$code, \%hashSol)==1){
print "Ceci est un PSL\n";
}
else{
print "Ceci n est pas un PSL\n";
}
print "CODE= ".$code."\n";
my ($refh) = \%hashSol;
return $refh; #retourner la référence sur la hashmap
} |
Partager