in reply to "use" vs "require"

and others with require (require "Simple.pl").

Files with no package should be included using do, not require or use.

Replies are listed 'Best First'.
Re^2: "use" vs "require" vs "do"
by Joost (Canon) on Aug 07, 2006 at 17:21 UTC
    Erm... why?

    It seems to me that the main difference between require and do is that do FILE will always load and execute the code, while require will only load it once:

    From require:

    ... "require" demands that a library file be included if it hasn’t already been included. The file is included via the do-FILE mechanism, which is essentially just a variety of "eval". ...

      Exactly. require will mysteriously fail if two modules need to use the file. It's a good habit to use do instead. You never know what someone will do in the future.

      There's another reason. Using do over require conveys more information to the reader. Since modules must not be loaded using do, it's safe to assume something loaded using do is not a module. Using require wouldn't be as clear.

        THANK YOU 'ikegami. I had the mysterious fail problem using require. Changed it to 'd', and things are fine. Thanks for sharing your insite. jfb