Realistically, it's quite unlikely that switching all your global variables to lexicals will significantly affect your script's performance, unless the script is CPU-bound rather than IO-bound.

Your "hack" puzzles me, because you are describing a conversion of implicit local variables to explicit package-specified global variables, not local to lexical. Regardless, there are serious problems with any automated approach, and I would never attempt such a thing.

Perl is virtually impossible to parse, and even a "simple" substitution can lead to nasty, unexpected results. If your substitution actually succeeds, you would immediately break any code that accesses the symbol table directly, uses soft (symbolic) references, or relies on the stack behaviour of "local" (though this last problem can, I suppose, be eliminated by not converting locals in subroutines). Moreover, these would be elusive run-time bugs, rather than compile-time errors (even under strict), as values would quietly be set to undef, and errors/warnings are reported from seemingly unrelated locations.

Additionally, turning all your subroutines into inner named subroutines may not necessarily be a source of bugs, but could easily lead to confusion. You also mention that you plan to run this under mod_perl, which means that you would have doubly nested named subroutines, and I don't even want to begin pondering the implications of that.

   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

In reply to Re: is 'my' that much faster than 'local'? by MeowChow
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.