unused lexicals

Discussion in 'Perl Misc' started by bill, Jan 30, 2004.

  1. bill

    bill Guest

    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
    bill, Jan 30, 2004
    #1
    1. Advertising

  2. 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;
    David K. Wall, Jan 30, 2004
    #2
    1. Advertising

  3. bill

    J Krugman Guest

    In <Xns94806FAC09692dkwwashere@216.168.3.30> "David K. Wall" <> 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
    J Krugman, Jan 30, 2004
    #3
  4. bill

    Matt Garrish Guest

    "J Krugman" <> wrote in message
    news:bveo03$f98$...
    > In <Xns94806FAC09692dkwwashere@216.168.3.30> "David K. Wall"

    <> 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
    Matt Garrish, Jan 31, 2004
    #4
  5. bill

    bill Guest

    Cool! Thanks, Matt.

    bill
    bill, Jan 31, 2004
    #5
  6. J Krugman <> wrote:

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

    <> 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>...
    David K. Wall, Feb 1, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas

    unused bits in signals

    Thomas, Jul 6, 2003, in forum: VHDL
    Replies:
    2
    Views:
    1,070
    Mario Trams
    Jul 6, 2003
  2. Mario Trams

    Re: unused input ports

    Mario Trams, Jul 22, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,102
    Mario Trams
    Jul 22, 2003
  3. Bob

    Re: unused input ports

    Bob, Jul 22, 2003, in forum: VHDL
    Replies:
    1
    Views:
    1,672
    Mario Trams
    Jul 22, 2003
  4. Neil Zanella

    unused wires and VHDL architectures

    Neil Zanella, Oct 20, 2003, in forum: VHDL
    Replies:
    3
    Views:
    1,427
    Peter Molesworth
    Oct 26, 2003
  5. cate

    BEGIN and lexicals

    cate, Jan 21, 2010, in forum: Perl Misc
    Replies:
    8
    Views:
    84
    RedGrittyBrick
    Jan 22, 2010
Loading...

Share This Page