in reply to Re^2: Propose addition to use warnings?
in thread Propose addition to use warnings?

Hi perldigious,

... I wouldn't be surprised if there were cases where it made good sense to do so.

I think choroba showed an excellent example of code where it's perfectly ok to pass a closed filehandle to a sub. I think usually it's the job of modules like Perl::Critic to enforce a certain coding style, not the job of warnings.

I agree that validation for a filehandle would be good if it was a trivial thing to do.

The code I showed with Scalar::Util will work in many cases, but not every single one. So it really depends on whether you're coding a module which you intend to release to many users, where the chances are good that someone might try to pass in a valid object that fails the test, or whether you're coding "just" a script where you've got a good overview of the values that are being passed to the sub. If it's the latter, then my approach would probably be to just use the code I showed, and if someday I decide I want to pass in something that fails the check, I can always reevaluate then.

Regarding your other reply about opening the files early in your scripts, note you could use file tests to check on the files at the start of the script so you don't have to open them right away. There is a small chance they might get deleted in between the file test and the open, but there's plenty of situations where one can safely assume that won't happen.

Regards,
-- Hauke D

  • Comment on Re^3: Propose addition to use warnings?