Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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
[oiskuu]: You want to draw the path? $iter = combinations( $TOP_HEIGHT .. $NODE_HEIGHT, $pos); then get the path from the iter, level change at depth x, for(..) $pos += $level_change; something like that
[oiskuu]: yergh, <code> tags... [$top_height .. $node_height]
[Eily]: Discipulus by demonstrate I suppose you mean simulate with perl?
[Eily]: the demonstration itself is fairly easy. The number of paths on a node is the sum of the numbers of paths to the two nodes above (or one node above on the edges of the triangle)
[Eily]: since the value of a node is also the sum from the two nodes above, you just have to demonstrate that the equality is true at the top of the triangle
[Discipulus]: yes Eily, thanks oiskuu but i dont get it.. ;=( maybe I'll ask a SOPW
[LanX]: all combinations with same amount of left and right?
[Eily]: if you want to store in a structure with the coordinates as key, arrays might do, since the keys are going to be 0..n

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2018-03-19 11:13 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.