Esteemed Monks,

I have a script foo.pl and a module Bar.pm both located together in a directory /my/stuff . In foo.pl I have:

use Bar; ...etc
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:
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 .)
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.