Xxaxx has asked for the wisdom of the Perl Monks concerning the following question:
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:
As one would expect. However this code does not work:#!/usr/local/bin/perl -w use strict; use 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) = get('http://www.newbie.org/index.html'); print $content;
So, I can make the routine run okay.#!/usr/local/bin/perl -w use strict; require LWP::Simple; my ($content) = LWP::Simple::get('http://www.newbie.org/index.html'); print $content;
Thanks in advance
Claude
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: use vs. require in LWP::Simple
by ton (Friar) on Apr 22, 2001 at 12:50 UTC | |
by Xxaxx (Monk) on Apr 22, 2001 at 13:50 UTC | |
by repson (Chaplain) on Apr 22, 2001 at 16:45 UTC |