At 01:51 PM 6/15/2001, you wrote:
>It is fairly unperlish to have large blocks of variable declarations at
>the top of a subroutine so throw away variables (like a one used only
>within a loop) tend to get declared as they are used. The only reason I
>can think of that would make it faster is that declaring $i this way
>tells the compiler that $i is not going to be permanently stored, so it
>may stay in a register.
Speaking only of the foreach my $var (@... idiom, I would agree with the
Perlishness, but there are other really good and valid reasons to use my to
declare your variables, beside purely stylistic ones. I would discuss them
myself, but I will let someone much more enlightened than I do the
talking. Check out the link below for a bunch of really good info about
variable scoping and Perl's operators for doing so. (Thanks again to
Mark-Jason Dominus.)
http://perl.plover.com/FAQs/Namespaces.html
I don't think this document has been updated to cover the new keyword
our. Check out perlfunc for that.
I would write a really brief synopsis, but I think that would be very
counterproductive in this case. I implore everyone to read *please* read
this document. I think the lucid and elegant explanations will clear up
much FUD and confusion about package and lexical variables. And I think it
will help many of us to make sense of some of Perl's features. Oh, BTW,
package and lexical variables have nothing to do with each other. Mr.
Dominus mentions this (prominently) in his FAQ above, but it is worth
mentioning here. Lexicals (my variables) and package variables (local, our
variables) have *not a thing* to do with one another.
Later,
Sean.