Update: can't believe I missed an important point. This is only if these are declared in a seperate block. D'oh.
my $x; if($test) { my $z; func(); } sub func { #cant see $z #can see $x since the sub is in the same scope as $x }
Mea Culpa.
1.Is there any difference between declaring variables at the beginning of scripts with my or our? Won't their
scope be the same?
2.Is there a reason to use one or the other in this situation
1. The scope is the same. our variables cannot be used outside the current file (unless they are declared in the other file of course). In the file there is an important difference though. our variables can be seen in subroutines and my variables declared at the top of your script cannot be seen inside your subroutines. You must pass them in.
2. If you don't want your subs to see the variables without being passed in ( ie as global ) then you should use my.
In reply to Re: Our, use vars, and magic, oh my!
by dga
in thread Our, use vars, and magic, oh my!
by OzzyOsbourne
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |