Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > unused lexicals

Reply
Thread Tools

unused lexicals

 
 
bill
Guest
Posts: n/a
 
      01-30-2004



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

 
Reply With Quote
 
 
 
 
David K. Wall
Guest
Posts: n/a
 
      01-30-2004
bill <no_spam@no_spam.com> wrote:

> 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;
 
Reply With Quote
 
 
 
 
J Krugman
Guest
Posts: n/a
 
      01-30-2004
In <Xns94806FAC09692dkwwashere@216.168.3.30> "David K. Wall" <(E-Mail Removed)> writes:

>bill <no_spam@no_spam.com> wrote:


>> 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;


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


 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      01-31-2004

"J Krugman" <(E-Mail Removed)> wrote in message
news:bveo03$f98$(E-Mail Removed)...
> In <Xns94806FAC09692dkwwashere@216.168.3.30> "David K. Wall"

<(E-Mail Removed)> writes:
>
> >bill <no_spam@no_spam.com> wrote:

>
> >> 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;

>
> 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


 
Reply With Quote
 
bill
Guest
Posts: n/a
 
      01-31-2004


Cool! Thanks, Matt.

bill

 
Reply With Quote
 
David K. Wall
Guest
Posts: n/a
 
      02-01-2004
J Krugman <(E-Mail Removed)> wrote:

> In <Xns94806FAC09692dkwwashere@216.168.3.30> "David K. Wall"

<(E-Mail Removed)> writes:
>
>>bill <no_spam@no_spam.com> wrote:

>
>>> 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;

>
> 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>...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BEGIN and lexicals cate Perl Misc 8 01-22-2010 03:50 PM
remove unused networks? Limbo Wireless Networking 0 07-02-2005 11:02 AM
Re: unused input ports Bob VHDL 1 07-22-2003 09:24 AM
Re: unused input ports Mario Trams VHDL 0 07-22-2003 08:18 AM
unused bits in signals Thomas VHDL 2 07-06-2003 10:22 PM



Advertisments