On Wed, Jan 28, 2004 at 01:32:14PM -0500, [EMAIL PROTECTED] wrote:
> Hi, this question has to do with importing names from one package into
> another. In my case, both packages reside in the same file, and I
> simply want to import all the package-global symbols from the one
> package into the other. Can anyone say how to do this? Here's a
> bunch of tries that didn't work.
Thanks for showing what you've tried. First couple snipped.
> Another variation:
>
> test_import.pl
> --------------
> package main;
> import SomePackage (qw(dosomething));
> print "Hi world\n";
> $x = dosomething();
> print "did something and got $x\n";
> exit;
>
> package SomePackage;
> use Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw(dosomething);
> sub dosomething{
> return time;
> }
>
> outcome:
> --------
> (Not what I expected; why didn't it tell me main::import is undefined?)
> Hi world
> Undefined subroutine &main::dosomething called at test_import.pl line 5.
This one will work if you swap the order of the two packages in the
file. Last example snipped.
> That's it. Any ideas?
This might be simpler:
package main;
*dosomething = \&SomePackage::dosomething;
print "Hi world\n";
$x = dosomething();
print "did something and got $x\n";
exit;
package SomePackage;
sub dosomething{
return time;
}
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>