in reply to How can I create an array of filehandles?
The trick is doing someting like:
After that you can use $file as a normal file handle so you can do:open(FILE, "myfile.txt") $file = *FILE
So here is how to put it all in an array:print $file "Hello File"; close $file;
#!/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++; }
In Section
Seekers of Perl Wisdom