[Za-pm] perl Command line switch

Jim Keenan jkeen at verizon.net
Wed Oct 6 10:28:40 CDT 2004


> 
> From: Spike <spikeh at mweb.co.za>
> Date: 2004/10/06 Wed AM 08:53:17 EDT
> To: Za-pm <za-pm at mail.pm.org>
> Subject: [Za-pm] perl Command line switch
> 
> Hi All
> It's very quiet out there - guess we must all be too good to have problems :-)
> 
> Is there a -w type of flag that will list all the variables I have declared 
> with 'my' but have not used?

Of the top of my head, I know of no such flag.  But it would be relatively easy to write a script which processes your Perl script line by line, notes which variables have been declared with 'my' and then sets a flag when such variables are subsequently encountered.

> I have some horribly messy scripts that have been growing over the last 
> year and need a good clean out!
> ... for that matter is there and easy way to list sub-routines that don't 
> get used? (probably not)
> 
If your script is crowded with extra subroutines, why not extract them into a separate file which is then 'require'd.  Or better still, place them in a module where each subroutine is exported only on request (i.e., not by default).  

That doesn't exactly tell you which subs are not used ... but it does clean up the mess in the main package.  (There is probably some elegant way to do this, say, with Devel::Cover, but I don't have time to think about that now.)

Jim Keenan
Brooklyn, NY



More information about the Za-pm mailing list