on 3/11/02 3:05 AM, [EMAIL PROTECTED] purportedly said:

> if i have a bunch of require's happening and all those
> required files happen to use some of the same named subs.
> how do i make sure my program uses exactly the one i want?
> 
> in mod_perl it seemd straightforward but what do i do in a
> normal perl-program?
> 
> mod_perl:
> my $dbh = Apache::somewhere::db::connection::connection_postgres::get_sub();

There is no way, automatically, using "require". Some alternatives, in order
of complexity:

1) Make sure to use "package" in your required files to declare their own
namespace (most Perl modules do), and then only invoke functions using their
full qualified name, e.g. Package::subroutine(). This is apparently what you
are doing with mod_perl.

2) Use "use" instead and follow export semantics so only the functions
specifically asked for are imported into the main namespace. Just about any
Perl book that covers modules will tell you how to do this, and it is fairly
simple.

3) Use object orientation instead. All namespaces are kept separate, so you
get the benefits of both #1 and #2, although much easier to manage and debug
than #1, as well as many other benefits to OOP implementation.


Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"

Reply via email to