le handle de fichier est il parametrable?
am 30.08.2006 15:21:33 von lepetitjoe
Salut
je voudrais parametrer l=B4ouverture pour lecture de certains fichiers,
et cela de cette maniere:
#################
open (FIC, "
file";
foreach my $value(@file){
$cpt=3D$cpt+1;
open (FILE$cpt, "
cannot read file";
@file$cpt=3D;
print FIC @file$cpt;
}
close(FIC);
$cpt=3D0;
foreach my $value(@file){
$cpt=3D$cpt+1;
close(FILE$cpt);
}
##################
le nombre de fichiers (docu1initial.html ,docu2initial.html ...)
variant, j peux fixer le nombre ds le programme, foit tout d´ábord
savoir combien sont present ds le repertoire courant et les mettre ds
un tableau (@file), ensuite parcourir le tableau pr traiter 1 a 1
($value(@file))
Mais j=B4ai ces messages d=B4erreur a l=B4execution:
1-Scalar found where operator expected at ./prog.pl line 1409 near
@file$cpt
(Missing operator before $cpt?)
2-Missing comma after the first argument to open function at ./prog.pl
line 1407, near " "
je ne vois pas les pieges , quelqu=B4un pourrai aider? =20
=20
a bientot
Re: le handle de fichier est il parametrable?
am 30.08.2006 16:14:03 von Paul Lalli
lepetitjoe@caramail.com wrote:
> Salut
>
> je voudrais parametrer l=B4ouverture pour lecture de certains fichiers,
> et cela de cette maniere:
I'm sorry, I don't speak French. If you don't speak English, hopefully
you can use Babelfish to translate this for you. . .
> #################
>
> open (FIC, "
> file";
>
>
> foreach my $value(@file){
> $cpt=3D$cpt+1;
> open (FILE$cpt, "
> cannot read file";
You want to be using an array of filehandles. See
$ perldoc -q "array of filehandles"
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq5.pod
How can I make a filehandle local to a subroutine? How do I
pass filehandles between subroutines? How do I make an
array of filehandles?
my @fhs;
my $i =3D 0;
foreach my $value(@file) {
open $fhs[$i++], '<', "repertoire/docu$cptinitial.html"
or die "error: Cannot read file: $!";
> @file$cpt=3D;
You cannot use another variable as the name to a variable. See:
perldoc -q "variable name"
my @file_texts; #declare this outside the loop
@{$file_texts[$i]} =3D <$fhs[$i]>;
> print FIC @file$cpt;
print FIC @{$file_texts[$i]};
>
> }
>
> close(FIC);
>
> $cpt=3D0;
> foreach my $value(@file){
> $cpt=3D$cpt+1;
> close(FILE$cpt);
> }
close $_ for @fhs;
I hope this helps.
Paul Lalli