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.
test_import.pl -------------- package main; print "Hi world\n"; $x = dosomething(); print "did something and got $x\n"; exit; package SomePackage; sub dosomething{ return time; } Obviously this isn't going to work because symbol dosomething is not defined in package main. (In this trivial example I could just say $x = SomePackage::dosomething(), but I have dozens of functions and I would prefer to simply import them into the namespace of main. Also, apart from this specific instance, I want to understand what I can do in general.) The documentation for perlmod implies there's an import method that's part of exporter, so I tried something like this. test_import.pl -------------- package main; SomePackage::import(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: -------- Undefined subroutine &SomePackage::import called at test_import.pl line 2. 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. Another variation: test_import.pl -------------- package main; use SomePackage; 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: -------- This obviously won't work because 'use' expects a module name, not a package name. Same issue with 'require'. Can't locate SomePackage.pm in @INC (@INC contains: d:/app/xampp/perl/lib D:/app/xampp/perl/lib D:/app/xampp/perl/site/lib .) at test_import.pl line 3. BEGIN failed--compilation aborted at test_import.pl line 3. That's it. Any ideas? __________________________________________________________________ New! Unlimited Netscape Internet Service. Only $9.95 a month -- Sign up today at http://isp.netscape.com/register Act now to get a personalized email address! Netscape. Just the Net You Need. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>