Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Package name overlap

by evgen-i (Novice)
on Feb 19, 2013 at 14:13 UTC ( #1019568=perlquestion: print w/replies, xml ) Need Help??
evgen-i has asked for the wisdom of the Perl Monks concerning the following question:


I have written a module called A module from the standard perl distribution has the same name. This was not a problem under Linux, but now I started using my script with Strawberry Perl under Windows. For some reason it loads the wrong module, namely the standard instead of my module!

Question: is there a way to keep my package name "English", but that the correct module is loaded?

My alternative would be to rename it to Preprocessing::English or something like that, but in that case I would prefer not to put the file in the Preprocessing/ subfolder, but keep it where it is now, namely where the script is that uses it. Is that possible?

Replies are listed 'Best First'.
Re: Package name overlap
by Dallaylaen (Pilgrim) on Feb 19, 2013 at 15:23 UTC

    Perhaps you're still better off renaming the module, here's why.

    Perl loads every module only once, see %INC in perlvar. So, if English is used internally by some other module down the road (which is likely, because it's 2012 and punctuation variables smell), it will not be loaded again. Instead, your module's import method will be called.

    But use English; exports a lot of stuff into the calling package, like $ERRNO etc. And suddenly a random module not even used directly by the code you control breaks with a syntax error message!

    Here's a little demo (run it as far as possible from your real!). Note the "not permitted" part is as planned (not a real error). The "echo 1" comand creates a correct empty module.

    -bash$ rm -bash$ perl -Mstrict -I. -wle 'use English; $ERRNO=1; print $ERRNO; ' Operation not permitted -bash$ echo 1 > -bash$ perl -Mstrict -I. -wle 'use English; $ERRNO=1; print $ERRNO; ' Global symbol "$ERRNO" requires explicit package name at -e line 1. Global symbol "$ERRNO" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
Re: Package name overlap
by ww (Bishop) on Feb 19, 2013 at 17:02 UTC
    So you're saying....

    I want a pony.

    As an alternative, I could accept a large dog, but in that case it would have to subsist on hay and oats and will have to live in the pasture I've already leased.

    Translated: Is there some really, really good reason why you want to fly in the face of standard practices... especially in a way that's almost guaranteed to bring you grief sometime in the (near?) future?

    PS: Clearly, I second AnonyMonk's final suggestion: pick better (for some value like 'Not in common use') module names.

    If you didn't program your executable by toggling in binary, it wasn't really programming!

Re: Package name overlap
by MidLifeXis (Monsignor) on Feb 19, 2013 at 15:18 UTC

    I would recommend renaming your module. The main reason (at least for me) is that the first module that you use requiring the core English module will be very confused.


Re: Package name overlap
by Anonymous Monk on Feb 19, 2013 at 14:17 UTC
Re: Package name overlap
by manorhce (Beadle) on Feb 19, 2013 at 14:33 UTC

    Yes use lib will work and it will load the module from the library which is provided by use lib but better go with include the directory to @INC at the beginning with unshift operator and call that through BEGIN block

    For example

    use FindBin qw($RealBin); use File::Spec::Functions qw(catdir); BEGIN { my @dirs = splitdir(canonpath($RealBin)); my($path) = grep { -e $_ } ( map { $_ = catdir(@dirs[0 .. $#dirs - + $_]).'pathtoModule' } (0 .. $#dirs) ); unshift(@INC, $RealBin, $path); }

    Please let me know if you have anything unclear and you

      Why not use?
      use FindBin qw( $RealBin ); use lib "$RealBin/../pathToModule";

      What do you think you're avoiding with your extra code block?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019568]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-01-16 15:59 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (151 votes). Check out past polls.