I'm working with LWP::Simple.

I have a small subroutine which will read in a webpage. Since I'm only using this subroutine on rare occasions I've decided to use 'require' rather than 'use' so that I'm not always eating the overhead of loading the full LWP module.

I am given to understand that require will load a module when the line is encountered during program flow and 'use' will load the module at the beginning. Please clue me in if that's not true.

The following code works just fine:

#!/usr/local/bin/perl -w use strict; use LWP::Simple; my ($content) = get('http://www.newbie.org/index.html'); print $content;
As one would expect. However this code does not work:
#!/usr/local/bin/perl -w use strict; require LWP::Simple; my ($content) = get('http://www.newbie.org/index.html'); print $content;
I can make the code work just fine if I change it to:
#!/usr/local/bin/perl -w use strict; require LWP::Simple; my ($content) = LWP::Simple::get('http://www.newbie.org/index.html'); print $content;
So, I can make the routine run okay.
But sometimes just poking around until stuff works is not enough. It would be nice to understand better why the middle form of 'require' without the 'LWP::Simple::' in front of the get doesn't work.

Thanks in advance
Claude


In reply to use vs. require in LWP::Simple by Xxaxx

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.