Yesterday I was (re-)refactoring some old code. My tests ran OK, so I was about to check the thing back in, when I decided to eyeball it one more time. To my surprise, I noticed I'd removed the last reference to a sub (in other words, it wasn't getting called from anywhere), and hadn't received any notice or warning, even though I was using strict and warnings.

I realized the warning I was thinking of is for "variable appears only once", not "sub appears only once". I went looking thru the docs to see if there was some way to coax Perl into telling me that I had dead code, but didn't find one. Searching through the monastery proved fruitless as well. The B::Lint module sounded promising, but it doesn't want to run on my box, and the docs don't mention catching this type of oversight anyway. This sounds so simple, I'm sure I'm overlooking something obvious.

So, fellow monks, how do I make Perl tell me I've got a sub that is not being referenced anywhere else in the program? Just a simple compile-time check would be plenty. It doesn't have to be bulletproof; some reasonably good hints would be OK.


In reply to Warnings for unused subs by VSarkiss

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.