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


In reply to Re: Question regarding "require" or "use" by davido
in thread 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.