Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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
|
|