Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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?

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
beech .oO( maybe i should start trolling ntc )

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2017-04-28 00:44 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (514 votes). Check out past polls.