in reply to Cleaning up unused subroutines

perl -ple"s[sub\s+(?=\w)][sub XXX_]g" yourscript.pl >junk.pl

Run junk.pl and correct each Undefined subroutine &..... called at ... by removing the XXX_ from the subroutine declarations. Once the script runs again, any sub definitions still carrying the XXX_ prefix are redundant and can safely be removed from yourscript.pl


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Cleaning up unused subroutines
by aquarium (Curate) on Oct 26, 2007 at 03:07 UTC
    BrowserUK -- as noted earlier, this doesn't produce 100% coverage in non-trivial code. Certainly not for code that gets released to a customer for a production system anyway. Good thinking outside the square.
    the hardest line to type correctly is: stty erase ^H

      Hm. I'm not for one moment going to suggest that you are wrong. If the code uses prototypes on one or more of the subs, then the regex would need modification. Likewise, as I coded it, it would ignore anonymous subs.

      But, for the sake of completeness, could you describe what other situations might not be covered?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        perl -wle 'foo() for @ARGV'

        foo() may or may not be called, depending on @ARGV. This is just a very simple example of the larger problem: subroutines may or may not be called based on conditions that can only be determined at run-time.

        The only way to really do this was covered earlier: with a comprehensive test suite and gradual code modification.