in reply to Question regarding "require" or "use"
I can replace use Bar; with require "Bar.pm"; and this seems to work.
Question: what effects does using 'require' instead of 'use' for a module have?
To quote Camel II:
use is exactly equivalent to the following:
BEGIN { require Module; import Module LIST; }
So it would seem that by using 'require' rather than 'use' you are missing out on importing from Module whatever it has to export. You also miss out on bringing the module in at compile time instead of runtime.
UPDATE: chromatic's followup is accurate and helpful. His solutions show how to direct Perl to the path of Foo.pm. The OP's use of the name 'Foo.pm' suggests a module, but it is in fact a filename, and requires that the full path be expressed. The portion about require not taking advantage of import and the BEGIN block is still relevant, and you can see by chromatic's solutions that the issue has to be delt with one way or another.
Dave
"If I had my life to do over again, I'd be a plumber." -- Albert Einstein
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Question regarding "require" or "use"
by chromatic (Archbishop) on Oct 02, 2003 at 18:23 UTC | |
by freddo411 (Chaplain) on Oct 02, 2003 at 21:30 UTC |