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