Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

'Using' modules

by hotshot (Prior)
on Aug 27, 2003 at 08:55 UTC ( [id://286983]=perlquestion: print w/replies, xml ) Need Help??

hotshot has asked for the wisdom of the Perl Monks concerning the following question:

Is there in Perl a #ifndef mechanizm like in C for example. I have some scripts that are sharing the same modules or does do to the same scripts, and I'm getting xxx redefined in yyy.. warnings, and of course I want to avoid that.

Hotshot

Replies are listed 'Best First'.
Re: 'Using' modules
by Abigail-II (Bishop) on Aug 27, 2003 at 09:12 UTC
    If you use require or use (the latter is usually preferred) then said warning shouldn't occur. Perl keeps track of which modules it has already compiled, and won't recompile a module unless you know which strings to pull. That is, as long as you use require or use. Note that the manual page about do also recommends the use of require or use.

    Abigail

Re: 'Using' modules
by dragonchild (Archbishop) on Aug 27, 2003 at 12:55 UTC
    I suspect that you have the same function names in different modules. Also, if you're useing or requireing, don't do. In fact, don't ever do.

    I have used do in production code to source in files exactly once in my career, and the file that was done had one (large) configuration variable in it. (That hack was removed in a later version.) do skirts too many safeguards, such as the built-in #ifndef mechanism that use and require provide.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      but I can't just do:
      use 'test.pl'; # or use 'test.ph';
      It shouts for syntax error, use argument suppose to be a module name, not a file name, so what else can I do?

      Hotshot
        Try require, then. Or, rewrite test.pl so that it fits the model for use. (I recommend the latter, simply because it's generally better.)

        ------
        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://286983]
Approved by valdez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found