in reply to Propose addition to use warnings?
Hi perldigious,
So as I understand it you would like the warning to be triggered when you use $first_fh as a parameter to my_sub? Note that's it's perfectly fine to re-use $first_fh after it was closed, so the warning can't just be "filehandle used after closing" or something similar, the trigger needs to be something more specific. But how Perl should know that the first parameter to my_sub needs to be an opened filehandle? This sounds like a case for parameter validation to me. At the top of my_sub: my $fh = shift; croak "argument must be an opened filehandle" unless ref $fh eq 'GLOB' && $fh->opened;. Update: Probably better: At the top of your script use Scalar::Util qw/openhandle/;, and at the top of my_sub: croak "argument must be an open filehandle" unless openhandle($fh); (Update 2: But see also Best way to check if something is a file handle?, identifying every kind filehandle-like thing appears to be nontrivial.)
Regards,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Propose addition to use warnings?
by perldigious (Priest) on Nov 28, 2016 at 18:58 UTC | |
by haukex (Archbishop) on Nov 28, 2016 at 21:17 UTC |