Hello Maggs,

>>>>>> KS >>>>>Ken Slater <kl...@psu.edu> wrote:

KS>>OP was using trying to use 'open_file' to open one file handle at a
time.
KS>>Arguments were presumably the file handle variable, mode, and  file
name.
KS>>Your example is very different.

I think 'KS' got the heart of what you really want, and in that light try if
this following code could help:

<code>
#!/usr/bin/perl -w
use strict;

my @arr=();
   my %hash_file=(file_handle=>'fh',file_mode=>'mode',filename=>'name');
    foreach(sort keys %hash_file){
       print "Enter your $_: ";
         chomp($hash_file{$_}=<STDIN>);
      push @arr,$hash_file{$_};
    }
  open_file(@arr);  # call the subroutine

  sub open_file{
    no strict "refs";  # use this because filehandle is an expression, that
is it's value
                               # is the real filehandle, which is considered
a symbolic ref.
                               # check *perldoc -f open* for more info.
         my ($fh,$mode,$name)=@_;
     open ($fh,$mode,$name) || die "can't open $!";
       while(<$fh>){ chomp;
           print $_,"\n";   # $_ takes the line you are printing out
       }
     close ($fh) || die "can't close file: $!";
  }
</code>

Regards,
tim

Reply via email to