Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Why do multiple requires not work?

by srinigs (Novice)
on Dec 06, 2012 at 11:45 UTC ( #1007543=perlquestion: print w/ replies, xml ) Need Help??
srinigs has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Supposing i have a module Mod.pm which has a statement "require /a/b/script" and there is a script run.pl which has the statements "use Mod" and "require /a/b/script", then, when any routine inside /a/b/script is called from run.pl, I get the "Undefined routine ..." error. This error does not appear when the require statement is removed from Mod.pm module, but the vice versa is not true (ie when I remove the require statement from run.pl and retain the one in Mod.pm, the error still persists).

Can you please explain why multiple use statements are not a problem but multiple "require" statements cause an issue?

Comment on Why do multiple requires not work?
Re: Why do multiple requires not work?
by DrHyde (Prior) on Dec 06, 2012 at 11:52 UTC

    require checks %INC to see if a file has already been loaded. This is explained in the documentation.

    use also checks %INC (because it is exactly equivalent to BEGIN { require Module; Module->import( LIST ); }) but regardless of whether the module was already loaded or not it still calls the import() method.

Re: Why do multiple requires not work?
by bart (Canon) on Dec 06, 2012 at 11:53 UTC
    You can't use slashes in the name of the required file. You can use either double colons, and no file extension (".pm" is assumed), or you can use a string (a quoted literal or a variable) with a path with slashes and with file extension. So you can do
    require "/a/b/script";
    if it has no file extension, or
    require "/a/b/script.pl";
    if it has ".pl" as file extension.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007543]
Approved by DrHyde
Front-paged by DrHyde
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-25 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (170 votes), past polls