Hi Maggs,

I don't know what you really wants to achieve with your codes below:

(open...)

sub open_file {
local $/ = undef;
($filevar, $filemode, $filename) = @_;
open ($filevar, $filemode . $filename) || die ("Can't open
$filename");
}
everytime i run it i get the error: Can't use string ("FILE1") as a
symbol ref while "strict refs" in use.

Any help please on how to sort this out.

I suppose you want to want to open some files using a subroutine, see if the
code below helps, and if not you may have to explain what you really want to
do.

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

    open_file(@ARGV);  # call the subroutine

  sub open_file{
    foreach (@_){  # iterate on the files to open
     open FH,"<",$_ || die "can't open"; # $_ takes the name of the file to
open
       while(<FH>){ chomp;
           print $_,"\n";   # $_ is the line you are printing out
       }
     close FH || die "can't close file";
    }
  }
</codes>
Note: You can call the FH, $fh if you like, but then you must use *my* with
strict in use. You can also use different names for $_, that depends on you.
Regards,
tim

Reply via email to