Dear perl programmers,
When using open(), please don’t use:
open FILE, "$file" or die "couldn't open filen";
It really helps if you tell us what file you’re trying to open and
what went wrong. The correct error message is:
open FILE, "$file" or die "could not open $file: $!n";
Thank you.
on said:
Hear hear!
On a side note: can I ask the stupid question where PivoxyWindowOpen comes from? Google gives too many false positives.
on said:
Hear hear!
On a side note: can I ask the stupid question where PivoxyWindowOpen comes from? Google gives too many false positives.
on said:
That should be addressed to all programmers, not just the perl hackers. We had a lot of trouble with these kind of error messages when we first had to install a software which acquires data from a lab machine. The installation was on a networked pc running windows and should of course only run with user rights. The only error message we got when we started the program as a user was that it couldn’t access some file (not giving the path nor the file name of the file). This kind of problem is much harder to trace down in a windows environment with compiled software than using Linux and perl scripts..
on said:
Also, modern perl should
open my $file, “filename” or die “Couldn’t open filename: $!”
since “my $file” will limit the scope of the handle.
on said:
Aren’t we all using IO::File these days? 🙂
on said:
Why would I “use IO::File” when I can just “open”?
Besides, this is the EXACTLY the same as
my $file = IO::File->open(“filename”) or die “Couldn’t open filename: $!”
on said:
Surely you mean:
open FILE, “<$file” or die “couldn’t open file: $!n”;
Otherwise it could be a security vulnerability, if $file is controlled by a remote user and starts with a “|” character.
on said:
Not really. That wasn’t part of the point I was trying to make. I intentionally left out the open action because my comments relate to all uses of open. In particular you failed to put the filename in the error message.
Also, tainting should protect you against using user data in an open command.
on said:
You probably want to read http://mail.python.org/pipermail/python-list/2003-August/178599.html