Salut,

Je fais un petit script pearl qui prend n parametres. Les n-1 premiers sont des fichiers a traiter, le dernier parametre etant le fichier dans lequel je veux ecrire des statistiques sur le contenu de fichier.
typiquement :
gen_data.pl file1 file2 file3 out_file

Dans mon gen_data.pl, je veux faire le meme traitement pour mes fichiers d'entre, d'ou mon idee d'utiliser sub. Malheureusement je n'arrive pas a passer corectement les file handle de mes fichiers d'entree a mon procedure sub.
J'ai donc du tmeporairement dupliquer la meme tache.
Mon script donne donc :
#!/global/local/2003.01/bin/perl
open(input1,@ARGV[0]) || die "Could not open @ARGV[0]";
open(input2,@ARGV[1]) || die "Could not open @ARGV[1]";
open(input3,@ARGV[2]) || die "Could not open @ARGV[2]";
open(output,">@ARGV[3]");


while (<input1>) {
chomp;
if (/^Pin/) {$debut = 1;next}
if ($debut==1) {
if (/^----.*/) {next}
if (/^1/) {next}
@mot = split(/[ ]+/,$_);
$point = $mot[0] . " " .$mot[1];
$coverage{$point}{1} = $mot[4];
$coverage{$point}{nbr}++;
}
}

$debut=0;
while (<input2>) {
chomp;
if (/^Pin/) {$debut = 1;next}
if ($debut==1) {
if (/^----.*/) {next}
if (/^1/) {next}
@mot = split(/[ ]+/,$_);
$point = $mot[0] . " " .$mot[1];
$coverage{$point}{2} = $mot[4];
$coverage{$point}{nbr}++;
}
}

$debut=0;
while (<input3>) {
chomp;
if (/^Pin/) {$debut = 1;next}
if ($debut==1) {
if (/^----.*/) {next}
if (/^1/) {next}
@mot = split(/[ ]+/,$_);
$point = $mot[0] . " ". $mot[1];
$coverage{$point}{3} = $mot[4];
$coverage{$point}{nbr}++;
}
}

Pas tres elegant et portable.
J'aimerai plutot faire :
#!/global/local/2003.01/bin/perl
open(input1,@ARGV[0]) || die "Could not open @ARGV[0]";
open(input2,@ARGV[1]) || die "Could not open @ARGV[1]";
open(input3,@ARGV[2]) || die "Could not open @ARGV[2]";
open(output,">@ARGV[3]");


sub cover {
while (@_) {
chomp;
if (/^Pin/) {$debut = 1;next}
if ($debut==1) {
if (/^----.*/) {next}
if (/^1/) {next}
@mot = split(/[ ]+/,$_);
$point = $mot[0] . " " .$mot[1];
$coverage{$point}{1} = $mot[4];
$coverage{$point}{nbr}++;
}
}

%coverage = cover(input1);
%coverage = cover(input2);
%coverage = cover(input3);

Malheureusment, je n'y arrive pas.

Comment faire pour que je puisse passer mes differents fichiers comme argument de ma procedure ?

Merci pour l'aide.