in reply to Re^2: Acceptable way to divide a long module into multiple files
in thread Acceptable way to divide a long module into multiple files
Thanks, tilly. I think what confused me was that I've been viewing the package as a lexical scope that could span files. Now I see that it is only a namespace and that the largest lexical scope in Perl is a file. Do I have that right?
To illustrate what (I think) tilly is saying (because I find it somewhat abstract):
#--------------------------------------------------------- # Foo_1.pm use strict; use warnings; package Foo; my $HELLO='elloHay'; our $GOODBYE ='oodbyeGay'; sub hello { "hi! $HELLO -> $GOODBYE"; } 1; #--------------------------------------------------------- # Foo_2.pm use strict; use warnings; package Foo; # You are right Tilly - "our" doesn't reset $GOODBYE # and strict won't complain about an unqualified our # variable so long as we declare it our $GOODBYE; print "GOODBYE=$GOODBYE\n"; # no compiler complaints from above line # outputs: GOODBYE=oodbyeGay $Foo::HELLO='Bonjour'; #this is OK $Foo::GOODBYE='Au revoir'; #this is OK print hello() . "Hello=$Foo::HELLO, Goodbye=$Foo::GOODBYE\n"; # in the hello() sub HELLO and GOODBYE are both unqualified. # the my variable(HELLO) retains its old value, but the our # variable (GOODBYE) reflects the new value because with # or without qualification it is global (in the package table) #outputs: hi! elloHay -> Au revoir: Hello=Bonjour Goodbye=Au revoir #NOT hi! elloHay -> oodbyeGay: Hello=Bonjour Goodbye=Au revoir #NOR hi! Bonjour -> Au revoir: Hello=Bonjour Goodbye=Au revoir
So, no bug.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Acceptable way to divide a long module into multiple files
by tilly (Archbishop) on Jan 12, 2011 at 09:05 UTC |