merlyn mentioned this in node
23958:
"In 5.6.0, the 'our' keyword is synonymous with 'use vars' to declare package globals."
Uh, no. Not quite. It's use vars but with lexical scoping, so if it's inside a block, it loses effect after the block.so i decided to do some checking. when i run:
use warnings;
use strict;
{
our $y = 17;
print "inner: $y\n";
}
print "outer: $y\n";
i get the following warnings:
Variable "$y" is not imported at tester.pl line 10.
Global symbol "$y" requires explicit package name at tester.pl line 10
+.
but when i comment out the "use strict", the code runs and i get:
inner: 17
outer: 17
so what happened? it seems like 'our' is similar to 'local' but it inputs the variable into the symbol table. this backs up merlyn's comment that its dynamically scoped. but it appears to stay defined outside of the block its declared in. is this a bug, or a special feature of 'our'?