in reply to Re: Need Unused Variable Warning Msgs
in thread Need Unused Variable Warning Msgs

It would fail on a simple piece of code like this:
{my $var;} {my $var;}
Both variables are unused. "Unused" would mean only declared in a certain scope, not only declared in the entire program.

Abigail

Replies are listed 'Best First'.
Re: Re: Need Unused Variable Warning Msgs
by samtregar (Abbot) on Jun 10, 2002 at 17:14 UTC
    Writing a regex that parses Perl scopes is left as an exercise for the reader. Ultimately that's what tools like lint have done for C - they actually parse the C code just like a compiler would and do pattern matching to find bad code.

    -sam

      Parsing C is orders of magnitude simpler than Perl. Not even perl can always pass Perl.

      But even if you have such a regex, to actually find out whether a variable is unused or not, you've got to know what a piece of code will do. To determine that at compile time, you need to solve the halting problem.

      If you solve the halting problem, I'll do the regex.

      Abigail

        So how does lint do it? Does it solve the halting problem? I think it would be sufficient to determine if a variable as created in a scope with my() or our() and then never mentioned in the scope again. That would be useful enough to be worth the occaisonal false-positive that would result from evals and other nefarious tricks.

        -sam