strict - Are there any differences between our defined variables and normal global variables in Perl? -


is our modifier used when strict pragma active let using global variables or used features different normal global variables when strict off?

yes, our declarations can have additional features when compared undeclared globals. these largely irrelevant.

our creates lexical alias global variable (of same name). is, in package foo, our $bar , $foo::bar refer same variable. however, former available in tight lexical scope.

as our has lexical effect, alias can shadow lexical variables my:

our $foo = 42; # give value  $foo = -1; # same name, different value "my  gives $foo"; our $foo;      # reintroduce alias; shadow lexical "our gives $foo"; 

if strip our declarations , run without strict, won't give output

my  gives -1 our gives 42 

just my, our can take bit declaration syntax, e.g. attributes:

use threads::shared; our $foo :shared; 

you can specify type usage fields pragma:

our foo $foo; 

this can't done global variables without our.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -