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
In reply to Question regarding "require" or "use" by freddo411
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |