You can insert file descriptors directly into an uninitialized array slot.
my @handles;
for my $number (0 .. 9) {
open $handles[$number], '>', "data$number";
}
Do not forget that the syntax for printing in the descriptor in the array is slightly different:
print $handles[3] $data;
print {$handles[3]} $data;
source
share