Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visibility of REQUIREd files in other REQUIREd files

Status
Not open for further replies.

Tyger

Programmer
Sep 19, 2001
21
GB
Hi, I have been programming Perl for years and should probably know this but it is one of those things I have never seen in black and white:

If I have a script like this:

...
require "subs.pm";
require "moresubs.pm";

$valueA = &somethingInSubs;
$valueB = &somethingInMoresubs;
...

Will a subroutine in my "moresubs.pm" file be able to call subroutines in "subs.pm" ? Or will I have to put 'require "subs.pm";' inside "moresubs.pm" ?

When I try it out it seems to work, but most books I have looked at try to avoid explaining scope and I have never had a straight answer to this. I don't really like rellying on something which 'seems' to work without being certain that it is supposed to function that way.

I know that it is safe to perform a 'require' multiple times as it will be ignored if it is found more than once, but it would be nice to know what is actually going on.

Many thanks,

 
'require' should be visible down to all children. I think the reason books shy away from explaining this is that any child can define their include paths and visible functions. So, while in the general case this works its not really proper.

Think of it as akin to creating global variables. Can you do it? Yes. Is it reliable? Not really. Does it have unintended side-affects? Yes, usually.

Its better to go with modules that export functions or support an object interface.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top