Home > Archive > PERL Programming > August 2006 > le handle de fichier est il parametrable?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
le handle de fichier est il parametrable?
|
|
| lepetitjoe@caramail.com 2006-08-30, 7:57 am |
| Salut
je voudrais parametrer l=B4ouverture pour lecture de certains fichiers,
et cela de cette maniere:
#################
open (FIC, "<repertoire/docufinal.html" ) || die "error: cannot read
file";
foreach my $value(@file){
$cpt=3D$cpt+1;
open (FILE$cpt, "<repertoire/docu$cptinitial.html" ) || die "error:
cannot read file";
@file$cpt=3D<FILE$cpt>;
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=B4=E1bord
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 " "<repertoire/docu$cptinitial.html" ) "
je ne vois pas les pieges , quelqu=B4un pourrai aider? =20
=20
a bientot
| |
| Paul Lalli 2006-08-30, 6:57 pm |
| 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, "<repertoire/docufinal.html" ) || die "error: cannot read
> file";
>
>
> foreach my $value(@file){
> $cpt=3D$cpt+1;
> open (FILE$cpt, "<repertoire/docu$cptinitial.html" ) || die "error:
> 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<FILE$cpt>;
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
|
|
|
|
|