in reply to Naming file handles with variables?

Your problem has been solved even before perl existed. 'paste' combines files in a column by column fashion. I'd use bits and pieces like these:
my $command = 'paste ' . join(' ', @ARGV); open FH, $command .'|'; while <FH> { @one_line = split "\t", $_; # do something }
But I suspect that that your application needs something more efficient, as the presented solutions preseted up to now cause many disk seeks. Ignoring caches there is a seek for each line of each file!

I'd 'slurp' all files into an @array[file_no][line_no] one after another. This is done linear and at once. If the array does not fit into RAM, I'd use Tie::File. See e. g. http://www.sysarch.com/Perl/slurp_article.html

Replies are listed 'Best First'.
Re^2: Naming file handles with variables?
by GrandFather (Saint) on May 01, 2009 at 07:38 UTC

    However 'Ignoring caches' and and other real world aspects of programming leads to bad decisions. In this case for example caching means that the line at a time technique is likely to scale very well for extremely large files whereas slurping the files is likely to lead to thrashing the hard disk even for fairly modest (by today's standards) file sizes.

    In general slurping is a bad design choice and for a line by line task such as indicated by the OP Tie::File is likely to be (at best) little more than syntactic sugar, and at worse may impose significantly more overhead than the multiple file handle solutions already offered.


    True laziness is hard work