http://qs1969.pair.com?node_id=8882


in reply to How can I create an array of filehandles?

The trick is doing someting like:
open(FILE, "myfile.txt") $file = *FILE
After that you can use $file as a normal file handle so you can do:
print $file "Hello File"; close $file;
So here is how to put it all in an array:
#!/usr/bin/perl my @filehandles; #make array of 10 file handles for($i=0; $i<10; $i++) { #localize the file glob, so FILE is unique to # the inner loop. local *FILE; open(FILE, ">file$i.txt") || die; #push the typeglobe to the end of the array push(@filehandles, *FILE); } $count=0; #loop through the file handles. # treat $file as a normal file handle foreach $file (@filehandles) { print $file "File $count"; close $file; $count++; }