
use module; run subroutine
AB> I changed the package name to ``Archive::PassServer::Generic'' and
AB> thereafter the call to subroutine Archive::PassServer::Generic::hello()
AB> worked. So thanks for your help with that. But another problem emerged.
AB> I have other modules that define similar subroutines of the same name.
so don't do that! :)
AB> So for example, what I need to be able to do is something like this:
AB> use Archive::PassServer::Generic;
AB> use Archive::FileServer::Generic;
AB> use Archive::MailServer::Generic;
AB> Archive::PassServer::Generic::hello(); # print "Hello PassServer.\n";
AB> Archive::FileServer::Generic::hello(); # print "Hello FileServer.\n";
AB> Archive::MailServer::Generic::hello(); # print "Hello MailServer.\n";
AB> I eventually get the expected output:
AB> Hello PassServer.
AB> Hello FileServer.
AB> Hello MailServer.
AB> Subroutine hello redefined at /usr/libdata/perl/5.00503/Exporter.pm line 157
AB> Exporter::export('Archive::FileServer::Generic', 'main') called at /usr/libdata/perl/5.00503/Exporter.pm line 182
AB> I realize that in some sense there I'm redefining the subroutine hello(),
AB> but I figure that since I'm referring to the module names and hello()
AB> subroutines using what seems like absolute notation, I don't understand
AB> why there is a conflict.
explicitly import it in a use call, or explicitly don't import anything
by passing in a null list to use:
use Archive::MailServer::Generic () ;
you have set up the conflict so you have to figure out a way to stop
it. perl can't figure out which one you want so it warns you about the
redefines. either control your exporting or importing or don't do any
and call the functions by their fully qualified names. another solution
is to go OO with those modules and then you can have methods in
different classes with the same names. and with OO you don't
export/import anything. given the brief name space snippets above, OO
might be a good solution for you.
uri
--
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org