File handles - there must be a better wayby Anonymous Monk
|on May 13, 2013 at 16:11 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
I often find the need to open a fairly large number of input files simultaneously, to run line-by-line comparisons on them. I can not read in all of the complete files before starting my analysis - due to the large size the files, that would be a very slow and RAM-intensive approach.
The way I'm doing this now is horribly clumsy. I have an array of input file names, and then I have an array of arbitrary file handles, with at least as many elements as the former array, e.g.:
my @FileHandles = ('A', 'B', 'C'...'X');
I have a loop that opens all input files. Then to start reading them:
where "..." includes the retrieval of information from the current line of each file.
Today I found a need to read in over 100 files, and this has motivated me to find a more sensible way to deal with large numbers of concurrently used file handles. Is there a simple way to generate unique handles automatically for each element in my array of input files, without typing out a silly array like the @FileHandles shown above?
I've also found that at least when using double letter file handles from an array, I am forced to turn off 'use strict', which I otherwise keep on to catch typos.
Thanks for any help you can offer.