in reply to Question on "my" in the variables

If you have a code that runs perfectly fine, do you get more speed or something else if you use "my" and, in general, write the code more strictly?

my isn't magic, it doesn't make code run faster (maybe its half of a half of a half nanosecond faster if you're doing a million variables ... maybe )

Of course I know it should be with "my" etc, I am just wondering if there is another reason behind it except writing clean code.

clean code is the reason for 8/10 of the things you should be doing

Chances what you think is code runs perfectly fine probably isn't that fine with or without my -- this is like every new programmers experience :)

Have you read all these? Tutorials: Variable Scoping in Perl: the basics,
Coping with Scoping , Mini-Tutorial: Perl's Memory Management,
Lexical scoping like a fox,

Replies are listed 'Best First'.
Re^2: Question on "my" in the variables
by tobyink (Canon) on Feb 25, 2014 at 10:16 UTC

    Actually access to the pad (i.e. where lexical variables are stored) is about 40% faster than access to the stash (i.e. where package variables are stored).

    The issue is not so much about declaring a million variables, but accessing a few variables a million times. For example, if you're finding the average of a few million small numbers, you may notice the difference between package variables and lexicals.

    Though I agree that speed is not usually the main reason for preferring lexical variables over package variables. The avoidance of action at a distance is generally the most important.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name