Perl has two different and completely unrelated systems for creating variables.
Package variables (also sometimes known as global variables) are what you get if you just start using a variable without declaring it first. You can also explicitly create package variables with "use vars" or "our".
Lexical variables are created when you use "my".
You should be using lexical variables unless you have a good reason not to.
This is explained well by Dominus in his article Coping with Scoping. He also has a follow-up article Seven Useful Uses of local where he describes seven cases where you might want to use package variables instead of lexical variables.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: difference between my and local
by davorg
in thread difference between my and local
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |