THANX !!!!
----- Original Message -----
From: "Steve Grazzini" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, October 28, 2002 11:33 PM
Subject: Re: files
> Mark Goland <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > I am trying to read from file handles in a loop. What I want to do is
add a
> > string to a file handle. Here is an example of what I am tryin to do.
> > open FH1,"file";
> > open FH2,"otherfile";
> > ...
> > ...
> > foreach $Val (@F_handles){
> > @LINES=<FH$Val> # add $Val to handl name
> > }
> >
> > is it possible ??
> >
>
> Not like that :)
>
> You can look up the symref ahead of time:
>
> for my $ix (@F_handles) {
> no strict 'refs';
>
> local *FH = *{"FH$ix"};
> my @slurp = <FH>;
> ...
> }
>
> Or pass it straight to readline():
>
> for my $ix (@F_handles) {
> no strict 'refs';
> my @slurp = readline "FH$ix";
> ...
> }
>
> But probably the best thing would be to put lexically
> scoped filehandles into an array.
>
> my @files = map {
> open my $fh, $_ or die "open: $_: $!";
> $fh;
> } @paths;
>
> for my $fh (@files) {
> my @slurp = <$fh>;
> ...
> }
>
> The fact that "open FH, ..." is implemented with a symref
> and a global variable is pretty well hidden, for the most
> part, but as soon as you start passing filehandles around
> or putting them in data structures, you need to switch to
> real references.
>
> HTH
> --
> Steve
>
> perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]