Brandon McCaig wrote:
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': $!";
That won't work as the first argument to open is forced into scalar context
$ perl -le'print prototype "CORE::open"'
*;$@
so if @_ contains three elements that becomes:
open 3 or die "Can't open '$filename': $!";
And why is $filename not passed into the subroutine?
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/