in reply to Re: Re: is 'my' that much faster than 'local'?
in thread is 'my' that much faster than 'local'?

zenmaster wrote:
But they often can achieve the same result.
And usually people use them without even noticing the difference...
Well, let's look at a few other things that people use "without even noticing the difference":

Run the following code:

use strict; use warnings; print test(); sub test { local $x; $x = 17; }
Guess what? That generates an error similar to the following:
Global symbol "$x" requires explicit package name at C:\WINNT\Profiles +\Ovid\Desktop\test.pl line 7
That's because local does not create variables. Replace the local with a my and it works fine.

For more information, see Coping with Scoping and Seven Useful Uses of local. Both, oddly enough, were written by Dominus, the monk you chose to take to task.

Cheers,
Ovid

Update: After chatting with zenmaster and reading his update, I see that this mostly appears to be a misunderstanding of what he meant to say, but I'll leave the post as it's useful information.

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.