Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Opening multiple filehandlers

by btrott (Parson)
on Apr 06, 2001 at 11:28 UTC ( [id://70421]=note: print w/replies, xml ) Need Help??


in reply to Opening multiple filehandlers

How about using Symbol:
use Symbol; my $N = 15; my @FH; for my $i (0..$N-1) { my $fh = gensym; open $fh, ">$i.txt" or die "Can't open $i.txt: $!"; push @FH, $fh; }
Now all of your filehandles are in @FH, and you can loop through there and do what you will with them. Will this work for you?

Note that in Perl 5.6.0 you can just do:

open my $fh, ">$i.txt" or die "Can't open $i.txt: $!";
And it Just Works. You could then take out the 'use Symbol' and 'gensym' bits.

Replies are listed 'Best First'.
Re: Re: Opening multiple filehandlers
by leons (Pilgrim) on Apr 06, 2001 at 12:05 UTC
    Yep. It works perfectly ! Thanks

    Aha, I didn't know the fact that you could use:
    open my $fh, ">$i.txt" or die "Can't open $i.txt: $!";
    in Perl 5.6.0.

    I tried something similar on a system that ran a lower version
    and I couldn't get it to work. But knowing that this works in
    Perl 5.6.0, really makes life lots easier !!!

    I'm a happy man ;-)

    Thanks,

    Leon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://70421]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-20 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found