use strict ; use warnings ; my $lsub ; # visible in the packages that follow foo::z() ; # Initialise $foo::foo_global bar::z() ; # Initialise $bar::bar_global # Show that $foo_global is visible in package bar:: print "After $lsub: \$bar\::bar_global eq '$bar::bar_global'\n" ; # Show that $lsub was set by bar::z() # Show that $bar::bar_global is accessable by its full name my $b = foo::b() ; # Initialise foo::b()'s our $fred & return subroutine to access same print "After $lsub: &\$b() eq '", &$b(), "' eq \$foo\::fred eq '$foo::fred'\n" ; # Show that our $fred in foo::b() refers to $foo::fred # Show that $foo::fred is accessable by its full name my $a = foo::a() ; # Initialse foo::c()'s our $bill & return subroutine to access same my $c = foo::c() ; # Initialse foo::c()'s our $bill & return subroutine to access same foo::c() ; # Set foo::c()'s our $bill print "After $lsub: &\$a() eq '", &$a(), "' eq \$foo\::bill eq '$foo::bill'\n" ; # Show that foo::a()'s our $bill is the same as foo:c()'s # ... which is $foo::bill foo::a() ; # Set foo::a()'s our $bill print "After $lsub: &\$c() eq '", &$c(), "' eq \$foo\::bill eq '$foo::bill'\n" ; # Show that foo::c()'s our $bill is the same as foo:a()'s # ... which is $foo::bill package foo ; our $foo_global ; sub a { $lsub = 'foo::a()' ; our $bill = 'foo::a -- \$bill' ; return sub { $bill ; } ; } ; sub b { $lsub = 'foo::b()' ; our $fred = 'foo::b -- \$fred' ; ### my $q = $bill ; # Global symbol "$bill" requires explicit package name... # Remove '###' to show $bill is "out of scope" under use strict 'vars' return sub { $fred ; } ; } ; sub c { $lsub = 'foo::c()' ; our $bill = 'foo::c -- \$bill' ; my $q = $foo::fred ; # Show that we can access the global by its full name return sub { $bill ; } ; } ; sub z { $lsub = 'foo::z()' ; $foo_global = 'foo_global' ; } ; package bar ; our $bar_global ; sub z { $lsub = 'bar::z()' ; $bar_global = 'bar_global' ; print "$lsub: \$foo_global eq '$foo_global'\n" ; } ;