LWP Basics

Figure 9.1 shows a script that downloads the URL given on the command line. If successful, the document is printed to standard output. Otherwise, the script dies with an appropriate error message. For example, to download the HTML source for Yahoo's weather page, located at http://www.yahoo.com/r/wt, you would call the script like this:

Figure 9.1. Fetch a URL using LWP's object-oriented interface

% get_url.pl http://www.yahoo.com/r/wt > weather.html

The script can just as easily be used to download a file from an FTP server like this:

% get_url.pl ftp://www.cpan.org/CPAN/RECENT

The script will even fetch news articles, provided ...

Get Network Programming with Perl now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.