You're right, I had been confused about lexical scope. I assumed a lexical was scoped to its package, but it is actually scoped to its enclosing block (in this case, the file).
Between your explanation and chromatic's (below), this is a great discussion!
So, I went to my Perl books to try to find this explanation (to see which sections I have apparently never read). Camel Page 107-108:
...lexically scoped declarations have an effect only from the point of the declaration to the end of the innermost enclosing block. ... But a package declaration merely declares the identity of the default package for the rest of the enclosing block.Well, there it is. Packages do not define a namespace for lexical variables, because they do not define an enclosing block.
I believed, in my code, that lexical variables were "scoped" to their package. (I almost *never* use global variables... package globals or otherwise. Without my habit of mying every variable, I would not have stumbled across this (and lost an opportunity to learn even more)) :-)
All of a sudden, my version of reality is being updated. ;-)
I agree about my other question. grep and sort are obviously highly optimized. The coolest thing is, I haven't been able to find a crossover point (where sort grep become slower than max). No matter how large the data set, and no matter how many elements must be sorted, it is still faster to do the sort algorithm than max. It should be amazing, but this is Perl, where miracles are commonplace... :-)
Russ
In reply to RE:(2) Benchmark.pm's scoping behavior
by Russ
in thread Benchmark.pm's scoping behavior
by Russ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |