Today I wrote a script in which I had a sub declaration near the top:
sub chk_timer;
then at some point one or more lines like
chktimer $_ for @timers;
and at the end the actual sub definition:
sub chktimer { # ... }
As you can see I mistyped the declaration, or changed my mind way through. Whatever, perl -c told me everything was OK. Incidentally, I always
use strict; use warnings;
However I couldn't spot that typo and what I got was a runtime error:
Can't access `chktimer' field in class Proc::ProcessTable::Process at +./scriptname.pl line 75
instead. BTW: unfortunately in this case, the condition in which the actual line(s) in which the (alleged) function call is executed is very rare, so I had to wait quite a while until I could spot that error.

Now, of course perl has no way to understand that chk_timer was a typo for chktimer, but I wonder if it could be sensible to have a warning about subs that have been declared but not defined.

I can foresee objections to such a proposal in terms of deliberate symbol table manipulations, but even then I'm not really sure what the best choice could be... this is just a meditation after all!


In reply to Warning for "unused sub declarations"? by blazar

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.