Ed James wrote:

> Can the lexical scope be changed, say to package or other scope?

Yes it can.  Here is an example that explicitly sets package scopes:

$ type pp.p
 package foo;

 $foo = "foo foo";
 $bar = "foo bar";

 package main;

 $foo = "main foo";
 $bar = "main bar";

 print "\$foo is $foo\n";
 print "\$bar is $foo\n";
 print "\$foo::foo is $foo::foo\n";
 print "\$foo::bar is $foo::bar\n";
 print "\$main::foo is $main::foo\n";
 print "\$main::bar is $main::bar\n";

Here are some test runs:

$ perl pp.p
$foo is main foo
$bar is main foo
$foo::foo is foo foo
$foo::bar is foo bar
$main::foo is main foo
$main::bar is main bar
$ perl -w pp.p
$foo is main foo
$bar is main foo
$foo::foo is foo foo
$foo::bar is foo bar
$main::foo is main foo
$main::bar is main bar
$ perl "-Mstrict" -w pp.p
Global symbol "$foo" requires explicit package name at pp.p line 3.
Global symbol "$bar" requires explicit package name at pp.p line 4.
Global symbol "$foo" requires explicit package name at pp.p line 8.
Global symbol "$bar" requires explicit package name at pp.p line 9.
Execution of pp.p aborted due to compilation errors.
%SYSTEM-F-NOLOGNAM, no logical name match

You should also know that you can do tricky things with typeglobs
that involve the * character as discussed in perl_root:[pod]perlref.pod

HTH

Peter Prymmer

Reply via email to