P
pgl0338
I am trying to open an arbitrary number of files.
I hoped to put the file handles into a hash.
I am leaning-upon some code from pg. 194 of the Programming Perl 2nd edition
(FileHandle module)
In the following sample, the opens succeed (do not die), but the reads fail.
Thanks in advance!
pgl
#!/usr/bin/perl
use FileHandle;
&getInput;
foreach $iv (@files){
#.................................................#
# here's where I hope to eventually use the files #
#.................................................#
print "file: $filename{$iv}: ";
$line = <$FH{$iv}>;
print "$line";
}
sub getInput{
$lookingForFiles = 1;
while ($lookingForFiles){
print "file name > ";
chomp ($fn = <STDIN>);
if (-f $fn){
push @files, ($fn);
$FH{$fn} = new FileHandle
}else{
$lookingForFiles = 0;
}
}
foreach $name (@files){
$line = <$FH{$name}>;
print "line from $name:\n$line";
}
}
I hoped to put the file handles into a hash.
I am leaning-upon some code from pg. 194 of the Programming Perl 2nd edition
(FileHandle module)
In the following sample, the opens succeed (do not die), but the reads fail.
Thanks in advance!
pgl
#!/usr/bin/perl
use FileHandle;
&getInput;
foreach $iv (@files){
#.................................................#
# here's where I hope to eventually use the files #
#.................................................#
print "file: $filename{$iv}: ";
$line = <$FH{$iv}>;
print "$line";
}
sub getInput{
$lookingForFiles = 1;
while ($lookingForFiles){
print "file name > ";
chomp ($fn = <STDIN>);
if (-f $fn){
push @files, ($fn);
$FH{$fn} = new FileHandle
}else{
$lookingForFiles = 0;
}
}
foreach $name (@files){
$line = <$FH{$name}>;
print "line from $name:\n$line";
}
}