in reply to Arrays of files from an array of file names
Heh! I recognise some of that code :) _And_ you're planning to use one of my modules to do the array comparison.
In general, if you have a list of filenames and want to get a list of file contents then you'd better be sure that the files are small or you've got a lot of memory! That being said, you can do it like this:
my @files = qw(file1 file2 file3); my @contents; foreach (@files} { open FILE, $_ or do { warn "Can't open $_: $!\n"; next } local $/; push @contents, <FILE>; }
This gives you each file's contents in a scalar. To get an array of each file's contents you'd do this:
--my @files = qw(file1 file2 file3); my @contents; foreach (@files} { open FILE, $_ or do { warn "Can't open $_: $!\n"; next } push @contents, [<FILE>]; }
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Arrays of files from an array of file names
by Tuna (Friar) on Feb 18, 2001 at 19:56 UTC | |
|
What am I doing wrong?
by Tuna (Friar) on Feb 19, 2001 at 06:58 UTC | |
by japhy (Canon) on Feb 19, 2001 at 07:11 UTC |