SPUG: How to deal with same name packages?

David Dyck dcd at tc.fluke.com
Mon Jan 14 17:29:57 CST 2002

I asked cpan for the Link module that you guessed might
be conflicting with yours.

cpan>  look Link
Warning: Cannot look Link, don't know what it is.
Try the command

    i /Link/

It reports that there is no Link module (there are
thinks link WWW::Link, but that has a different name.

Does your code try to extract the name of
the class by using ref()?

You also may want to start up you code in the perl
debugger and type the command

x \%INC
x \@INC

to determine which modules are being loaded.

On Mon, 14 Jan 2002 at 14:24 -0800, c k <thasone at yahoo.com> wrote:

> Is there a way to deal with same name
> packages/modules/classes/objects in perl?
> I created a Link.pm and used that with LWP in a main
> script (e.g., put use Link; and use LWP; near the
> top).  I believe my Link.pm is clashing with another
> module named Link.pm in LWP, because when I change my
> Link.pm to Lynk.pm things work fine.
> Besides changing my module name from Link.pm to
> Lynk.pm, is there another way to deal with same name
> packages in Perl?  For example, in C you can do this,
> #if !defined LinkH
> #define      LinkH
> some stuff ...
> #endif
> Can I do that in Perl?  Is there a technique for doing
> that?

perl comes with a tool call h2ph
 (It may not do what you think you want,
  but it does defer execution via eval)

if you give it input like:
#if !defined LinkH
#define      LinkH

 some stuff ...


It creates a file like this:

require '_h2ph_pre.ph';

if(!defined (defined(&LinkH) ? &LinkH : 0)) {
    eval 'sub LinkH () {1;}' unless defined(&LinkH);

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/

More information about the spug-list mailing list