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


In reply to Re: Propose addition to use warnings? by haukex
in thread Propose addition to use warnings? by perldigious

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.