On Thu, Sep 22, 2011 at 4:54 AM, Maggs <maggiechimbwa...@googlemail.com> wrote: > ($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.
$filevar probably contains a value other than undef (apparently 'FILE1'), so open is trying to use its value as a symbolic reference (something that the strict pragma disallows). A symbolic reference basically means that the string contains the name of the variable to use. It's a very obscure and bad practice, which is why strict disallows it. Use a new variable or pass an already undef variable into open_file for the $filevar variable. See perldoc open. You should also be using the three-argument open instead of concatenating $filemode and $filename together. You should actually be able to just pass the arguments to open_file on to open directly: sub open_file { open @_ or die "Can't open '$filename': $!"; } # Call by using my to create $fh with undef, just like with raw # open: open_file my $fh, '<', 'foobar'; # Or undef the variable first: undef $fh; open_file $fh, '<', 'foobar'; (All of that is untested) May I ask what the purpose of open_file is anyway? It seems to be a simple wrapper over open that dies when open fails. Is that all it does? Perhaps you should see if autodie does what you want? See perldoc autodie. -- Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/