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

Hi

use warnings activates a check for typos in package variables.

Any chance to have the same for lexicals, which are never used?

To be more precise ... I want help to indentify code snippets which have become useless.

Any ideas?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re: "Only Used Once" warning for lexicals
by toolic (Bishop) on Aug 06, 2015 at 13:38 UTC
    perlcritic can identify a lexical variable which was declared with my, but was never set or used:
    use strict; use warnings; my ($unused, $i, $j); $i = $j; # uninitialized __END__ "$unused" is declared but not used at line , column 1. Unused variables clutter code and make it harder to read. (Severity: +3)

    See also:

Re: "Only Used Once" warning for lexicals
by Athanasius (Archbishop) on Aug 06, 2015 at 13:30 UTC
      warnings::unused claims itself unmaintained and recommends Test::Vars by the same author.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ