package Pack;
my $foo = 'pack';
sub import {
my $pkg = caller();
no strict 'refs';
*{ $caller . '::foo' } = \$foo;
}
1;
Now write a program:
#!/usr/bin/perl -w
use strict;
use Pack;
print "$foo\n";
After realizing that names have scope, variables do not (Dominus once said something similar), print out this page. Then eat it. :)
© | [reply] [d/l] [select] |
| [reply] |
So that's pretty ordinary. The only reason, I suppose, why it normally "can't be done" is that the inherited sub import can't get at them. It would have to be told of the ref, not the name. Perhaps extending the syntax to have ['$name' => \$name] in the @EXPORTS list would do the trick. That is, you must give the name (that the user of the package will ask for) and the ref, since it can't find a ref by itself just given the name.
—John
| [reply] [d/l] |