It would be difficult to
Benchmark a so-called typical script, since
the way the variables are used, how many there are, and what
kind they are would likely affect performace, gains or otherwise.
The "wrapper" approach seems interesting, but might be missing
out on some gains.
Why not this? A
'local' finder program that generates a list of
local
declarations using a loose regexp. You will have to prune
this because some things can't be declared using
my,
such as '$_' and filehandles, among others. Parsing Perl
perfectly (PPP?) is difficult, but this is a pretty specific
task, and any failures in parsing should be easy to
detect and correct. Perhaps, as a start (quick hack):
$_ = join ('', <STDIN>);
s/\blocal(\s*\(?([\$\@\%][a-zA-Z0-9_]*\s*,?\s*)+\)?\s*[;=])/my$1/g;
print;
Obviously a more sophisticated example would try and
figure out what is being declared, and avoid some traps
such as '
my ($_)'. I have tried to avoid
'my-ifying' strings which contain the word 'local' by
checking for a '=' or ';' somewhere in there, as well as
things that look like variables ($x, @x, %x).
The 'de-localizer' program, for lack of a better name,
would output a 'my-ified' version of any source you feed it.
You could diff the two, and edit the diff if any errors
crop up, or alternatively, write a second utility to analyse
the Perl warnings and automatically switch back to local
for those particular lines.
Just my $2e-2 worth.
Of course, this program could completely bust your logic
because of variable scoping issues that arise from the
subtle differences between local() and my(). Be sure to
test thoroughly.