in reply to Prohibiting redeclaration of lexicals in inner scope

I can't propose a detailed approach just now, but it would be along the lines of a perl script that would read perl code, look for declarations using "my", and normalize the text of these declarations so that you can look for duplicates easily. I have found B::Deparse to be useful in other cases where I wanted to look at perl code this way; it does an initial normalization of spacing around brackets and punctuation, making it a lot easier to look for things like subroutine definitions, variable declarations, etc.

You'd want something that takes code a line at a time, and spits out all the "my ..." declarations, one per line of output, with the line number in the original code (which is scrupulously preserved by B::Deparse, I think -- but even if it isn't, just edit the output of B::Deparse, 'cuz it's probably more readable than the original when there's a difference).

update: Here is an example using B::Deparse to tabulate sub defs and sub calls in perl code; might not be too big a stretch to make it focus on variable declarations instead.

  • Comment on Re: Prohibiting redeclaration of lexicals in inner scope

Replies are listed 'Best First'.
Prohibiting redeclaration of lexicals in inner scope
by JohnLon (Initiate) on Mar 31, 2003 at 16:19 UTC
    Thx but I'm only a novice and not really up to such a job.
    Was hoping someone had encountered this before.
    Bye JL
      I just hacked up a workable script to check for multiple uses of "my" with the same variable name -- find it here, under "cool uses for perl". It has its limitations, but perhaps it can be a useful crutch.