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
| #!C:\perl64\bin\perl.exe -w
use strict;
use warnings;
use diagnostics;
use 5.24.1;
# =======================
# Controle des paramètres
# =======================
unless (defined $ARGV[0]) {say "Vous n'avez pas renseigné votre premier paramètre !"; exit -1}
unless (-e $ARGV[0]) {say "Le fichier $ARGV[0] n'existe pas !"; exit -1}
unless (defined $ARGV[1]) {say "Vous n'avez pas renseigné votre second paramètre !"; exit -1}
unless (-e $ARGV[1]) {say "Le fichier $ARGV[1] n'existe pas !"; exit -1}
# ==================================
# Saisie du Nom du Fichier de Sortie
# ==================================
print "Choisissez un nom de fichier : ";
chomp(my $ficout=<STDIN>);
print "\n";
if (-e $ficout) {unlink $ficout;}
# ===================
# Lecture des Fichier
# ===================
my (@t,%hash);
open(FIC1, "<", $ARGV[0]) or die "Ouverture impossible fichier entrée $ARGV[0] : $!";
while (<FIC1>) { @t = split(/\s/,$_); $hash{$t[0]}{$t[2]} = 0.9 * $t[4]; };
close FIC1;
open(FIC2, "<", $ARGV[1]) or die "Ouverture impossible fichier entrée $ARGV[1] : $!";
while (<FIC2>) { @t = split(/\s/,$_); $hash{$t[0]}{$t[2]} += 0.1 * $t[4]; };
close FIC2;
# =================
# Tri et Sauvegarde
# =================
my ($k,@res) = (1,);
open(FICOUT, ">", $ficout) or die "Ouverture impossible fichier entrée $ficout : $!";
while (my ($i, $ref) = each %hash) { while (my ($j, $v) = each %$ref) { push @res, [$v,$i.' Q0 '.$j.' '.$k++.' '.$v]; }}
foreach my $i ( sort { $b->[0] <=> $a->[0] } @res ) { say FICOUT $i->[1]; }
close FICOUT;
exit |
Partager