in reply to Faster with my keyword or no ?
Perl's my lexical variables are not slow. They've been very heavily used in millions of lines of Perl code for many years now.
Instead of fretting about their performance, I suggest you spend your time understanding why they should be used in just about every Perl script you write. To get you started down that path, I've provided a few references below. After understanding the why, please feel free to post your code (using strict and my) for review.
If you have any performance concerns in any of your code, please present specific benchmark results first.
Why Using Strict and My Lexical Variables is Recommended
Stick to using only lexical variables (my) unless you genuinely need the functionality that only a package or punctuation variable can provide.
Using non-lexical variables increases the "coupling" of your code. If two otherwise unrelated sections of code both use a package variable, those two pieces of code can interact with each other in very subtle ways, just by the way they each interact with that shared variable. In other words, without full knowledge of every other piece of code that is called from a particular statement, it is impossible to know whether the value of a given non-lexical variable will somehow be changed by executing that statement.
-- Damian Conway in Perl Best Practices (Chapter 5: Variables)
|
|---|