[sf-perl] Can't use an undefined value as filehandle reference
Bill Moseley
moseley at hank.org
Wed Jul 6 15:01:46 PDT 2005
On Wed, Jul 06, 2005 at 01:09:46PM -0700, Vicki Brown wrote:
> No error with newer Perl (5.8.5 on my desktop).
Because in 5.8
If FILEHANDLE is an undefined scalar variable (or array or hash element) the vari-
able is assigned a reference to a new anonymous filehandle
I doubt that's true in 5.005.
>
> Here's the relevant code. The error is on line 5 in the example.
>
> #!/usr/bin/perl
>
> $szForm = "/www/private/nonexistent.txt";
>
> DisplayError ("tmail: template form [$szForm] could not be opened")
> if (!open ($file, "<$szForm")); # This line faults
That script starts out like:
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
not a good sign. use strict might be fun.
Why not rewrite as:
die "tmail: template form [$szForm] could not be opened: $!"
unless open FORM, "<$szForm";
Really, I'd dump that script.
--
Bill Moseley
moseley at hank.org
More information about the SanFrancisco-pm
mailing list