perlNinny has asked for the wisdom of the Perl Monks concerning the following question:

This only seems to keep the last file read:
use FileHandle; my @list; my $file; my @d = ("ds","DD","df"); foreach $type (@d){ $file = "list_".$type.".txt"; open (fh, "<$file"); @list = <fh>; close fh; } foreach $output (@list){ chomp $output; print $output."\n"; }
So how do I put ALL the lines from ALL the files into @list?

Replies are listed 'Best First'.
Re: Reading multiple files into array
by philcrow (Priest) on May 10, 2007 at 17:10 UTC
    When you say '@list = ...' the old value will be discarded and the new value will replace it. To get what you want, try push:
    push @list, <fh>;
    Phil
    The Gantry Web Framework Book is now available.
      Quote the Homer: D'OH That did it.
Re: Reading multiple files into array
by leocharre (Priest) on May 11, 2007 at 13:30 UTC
    unix 'cat' could be of interest to you. Perl versions are available on cpan.