Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Finding unused functions and vars?

by Jeppe (Monk)
on Oct 03, 2003 at 13:49 UTC ( #296238=perlquestion: print w/replies, xml ) Need Help??

Jeppe has asked for the wisdom of the Perl Monks concerning the following question:

Wise Ones,

How would you go about finding unused functions and vars in your code? The number of lines goes well into the thousands. Some code was made in more foolish times, and some was made before my time. I wish to locate functions that are never called, and variables that are never used.

Luckily, we use strict.

Do you have any tips or experiences to share?

Replies are listed 'Best First'.
Re: Finding unused functions and vars?
by liz (Monsignor) on Oct 03, 2003 at 14:00 UTC
    Maybe Devel::Cover is what you're looking for? I've never used it myself, but it is on my list of things to do for my own modules. If only to find out whether my test-suites are actually testing every aspect of my modules.


Re: Finding unused functions and vars?
by Juerd (Abbot) on Oct 03, 2003 at 14:06 UTC

    I wish to locate (...) variables that are never used.

    Let Perl do this for you. Whenever possible, don't declare variables before you use them.


    my ($foo, $bar, $baz, $quux, $blah);
    my $foo; my $bar; my $baz; my $quux; my $blah;


    my $foo = /aoeu/ ? 15 : 16; my $bar = Bar->new(); bless \my($baz), $class; open my $quux, '<', $file or die $!; my $bytes_read = read $quux, my($blah), $length;

    Juerd # { site => '', plp_site => '', do_not_use => 'spamtrap' }

Re: Finding unused functions and vars?
by BUU (Prior) on Oct 03, 2003 at 17:54 UTC
    heh. Heres an idea. First run a perl script to generate a Set containing all of the variables declared in your script. (<code>@set = m/($@%\w_+)/g<code> maybe..). Then delete all of the variables in the script and run it again under use strict. Create another Set containing all the variables strict complains about, then do a simple set intersection!

    (Ok, this probably wouldn't work. But it's a nice idea!)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://296238]
Approved by barrd
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2022-01-28 18:56 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (73 votes). Check out past polls.