Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm running into problems when I have nested required files.

For instance, I am growing the habbit of having a centralized index.cgi script, and then I require a sub.pl, for subroutines, and I require pages.pl, which holds the subroutines for each individual page. Within pages.pl, I require page1_html.pl or something along thoes lines.

Anyway, I wasn't getting errors for the first few scripts I've used this topology with, but I am now getting mutiple, crazy errors.

Is there a way to safely nest required files? Or am I out of luck, and need to keep it all in one big file.

Replies are listed 'Best First'.
Re: Multiple requires
by dragonchild (Archbishop) on Jul 16, 2001 at 20:26 UTC
    There're a huge number of potential issues that can arise in this type of situation. What are some examples of the crazy errors? What do some of your requires look like?

    Also, have you looked at creating modules that inherit from Exporter? That might solve a number of your issues, especially if you're talking about centralizing your subroutines, for example.

Re: Multiple requires
by MZSanford (Curate) on Jul 16, 2001 at 20:32 UTC
    When it comes to multiple nested requires, i often get into hot water with the paths. I tend to be one directory off in the path when doing a require 3 scripts deep and it it a holy hell to debug. My fix for this in the past 6-8 months has been to retro-fit all of my old require files into modules. I simply made a template with the package info at the top, and so my code change would be only one line, i commited to sin of adding all functions to @EXPORT against my better judgment. I have found this to be the best, long term solution.
    OH, a sarcasm detector, that’s really useful