Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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:


Supposing i have a module which has a statement "require /a/b/script" and there is a script which has the statements "use Mod" and "require /a/b/script", then, when any routine inside /a/b/script is called from, I get the "Undefined routine ..." error. This error does not appear when the require statement is removed from module, but the vice versa is not true (ie when I remove the require statement from and retain the one in, 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?
Replies are listed 'Best First'.
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/";
    if it has ".pl" as file extension.
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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2016-02-10 19:11 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (354 votes), past polls