I want to read in mulitple files from a directory and store each value in a unique variable so I can print it out later with a descriptive header. The file names have a common prefix, but are unique.
I know how to open up one file, but is there an efficient way to open up many files? or do i have open unique file handles for each one? thanks.
Filenames have a common prefix like (abc_*):
abc_foo_dir
abc_bar.dat1.20101208
abc_bar.dat2.20101209
Example opening up first file:
open FILE, "< /home/test/data/abc_foo_dir";
while (<FILE>) {
my $line = $_;
chomp($line);
print "$line\n";
}
close FILE;
You say “store each value in a unique variable”, but this is actually a task for a hash table.
You can iterate through all the keys later with
keys %file_contents, but if you aren’t familiar with how to work with hashes, I urge you to read perldoc perldata and perldoc perlsyn.