freddo411 has asked for the wisdom of the Perl Monks concerning the following question:
I have a script foo.pl and a module Bar.pm both located together in a directory /my/stuff . In foo.pl I have:
If my present working directory is /my/stuff and I run foo.pl everything is great. If my pwd is /somewhere/else and I execute /my/stuff/foo.pl I fail like so this:use Bar; ...etc
OK, so I could fix this by putting Bar.pm in one of the @INC dirs or by adding /my/stuff to the PERL5LIB ENV var prior to running the script. However, for several reasons, it would be much easier for me, and I would prefer to, modify foo.pl. Since the use statement is done at compile time, there is nothing I can do in the foo.pl script to keep the use Bar syntax if Bar.pm isn't already in the @INC.Can't locate Bar.pm in @INC (@INC contains: /usr/local/lib/perl5/5.005 +03/sun4-solaris /usr/local/lib/perl5/5.00503 /usr/local/lib/perl5/sit +e_perl/5.005/sun4-solaris /usr/local/lib/perl5/site_perl/5.005 .)
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?
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question regarding "require" or "use"
by davido (Cardinal) on Oct 02, 2003 at 17:54 UTC | |
by chromatic (Archbishop) on Oct 02, 2003 at 18:23 UTC | |
by freddo411 (Chaplain) on Oct 02, 2003 at 21:30 UTC | |
|
Re: Question regarding "require" or "use"
by TropicalD (Novice) on Oct 02, 2003 at 18:48 UTC | |
by Aristotle (Chancellor) on Oct 02, 2003 at 20:32 UTC |