in reply to Re: namespaces and variable initilization with require 'file'
in thread namespaces and variable initilization with require 'file'

Did you really mean to use the word 'modules' for both kinds of files? I guess in any case that you didn't mean that require can only be used on files with a package directive, because that's certainly not true:
$ echo 'print "Included a.pm\n";' > a.pm $ perl -e 'require a' # Included a.pm
works just fine for me. I understood a big difference (though by no means the only one) to be between whether you want to allow the file to be read multiple times, in the sense that
$ perl -e 'require a; require a' # Included a.pm $ perl -e 'do "a.pm"; do "a.pm"' # Included a.pm\ # Included a.pm
do different things.

Replies are listed 'Best First'.
Re^3: namespaces and variable initilization with require 'file'
by ikegami (Patriarch) on Oct 02, 2008 at 02:02 UTC

    The repeated use of "modules" was a copy and paste error.

    And right, I wasn't talking about the abilities of the respective commands, but their purpose. do executes a file. So does require. The difference is that require will only execute a file once per run, so it only makes sense to use require for files that load a module.