unused lexicals

B

bill

Is there a simple way to find the unused lexicals in Perl code?
By "unused lexicals" I mean lexicals that are mentioned only once
in their scope.

Thanks!

bill
 
D

David K. Wall

bill said:
Is there a simple way to find the unused lexicals in Perl code?
By "unused lexicals" I mean lexicals that are mentioned only once
in their scope.

use warnings;
 
J

J Krugman

use warnings;

I don't think this takes care of unused lexicals, as bill defines
them. At least, if I run the script

#!/usr/bin/perl -w
use warnings;
my $foo;
1;

I get no warning for the unused lexical $foo.

jill
 
M

Matt Garrish

J Krugman said:
In <[email protected]> "David K. Wall"


I don't think this takes care of unused lexicals, as bill defines
them. At least, if I run the script

#!/usr/bin/perl -w
use warnings;
my $foo;
1;

I get no warning for the unused lexical $foo.


One solution is to use B::Xref and parse the output to see whether a
variable is referenced only once:

Subroutine (main)
Package (lexical)
$foo i3

There are a number of limititations to this approach, but it's better than
nothing...

Matt
 
D

David K. Wall

J Krugman said:
In <[email protected]> "David K. Wall"


I don't think this takes care of unused lexicals, as bill defines
them.

Yes, I didn't read the OP closely enough. I even got email from someone who
would probably prefer to be left unnamed telling me about it. <open mouth,
insert foot>...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top