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.

In reply to Re: is 'my' that much faster than 'local'? by tadman
in thread is 'my' that much faster than 'local'? by gregw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.