SPUG: Predeclaring packages

Yitzchak Scott-Thoennes sthoenna at efn.org
Sat Jan 3 18:01:11 PST 2009


On Sat, January 3, 2009 4:18 pm, DeRykus, Charles E wrote:
> On Sat, Jan 03, 2009 at 12:14:08PM -0800, DeRykus, Charles E wrote:
>> #our $greeting = 'Hello there';     # not ok
>> $Hello::greeting = 'Hello there';   # ok
>> Hello::sayHi();
>> exit(0);
>>
>> package Hello; { our $greeting;
>> sub sayHi { our $greeting; print $greeting . "\n" } }

> Stranger yet it appears to work here:
>
> perl -wle 'our $x = 3; Foo::foo();  package Foo; sub foo { print $x};'
> 3

In your earlier example, you had an our later, in package Hello
(actually two).  Without that, it works:

our $greeting = 'Hello there';     # not ok
#$Hello::greeting = 'Hello there';   # ok
Hello::sayHi();
exit(0);

package Hello;
sub sayHi { print $greeting . "\n" }




More information about the spug-list mailing list