I don't understand the points you're trying to make. To me the "outside world" is everything that the perl script doesn't control. That includes all files you're trying to open.
If it doesn't exist, don't try to open it unless you are wanting to create it
Uhm. Trying to open a file for reading (which is the default mode of open) does not create it under any circumstance.
You also made the assumption that this file was in the "outside world" when that wasn't the case as per robertobouza's latest post
Since robertobouza post was a reply to mine, how could I have known what he was going to reply to me?
Even if it doesn't change in the mean time, there is absolutely no benefit in check its existence before trying to open it. Suppose you want to be thorough, then you'd have to write something like this:
if (!-e $file) {
die "'$file' does not exists';
}
if (!-r $file) {
die "insufficient permissions to read `$file'";
}
if (-d $file) {
die "`$file' is a directory, not a plain file";
}
# and so on
Actually there are error conditions (like out of memory) that you can't know in advance.
Instead you just do
open my $handle, '<', $file or die "Can't open `$fil'e for reading: $!"
And even if the file doesn't change in this case, it can't hurt to stop with bad practices now.
. If the file is locally on his machine then just hammering it to see if it works is not the answer...
Why not? I see no reason not just to try it. I hope I illustrated the reasons for doing so (large number of checks necessary; some checks are impossible to do in advance; danger of race conditions) |