[wplug] web programming

Eric C. Cooper ecc at cmu.edu
Tue Oct 28 11:28:27 EST 2003


On Tue, Oct 28, 2003 at 10:58:09AM -0500, Jonathan Billings wrote:
> On Tue, Oct 28, 2003 at 10:25:13AM -0500, John Harrold wrote:
> > #! /usr/bin/perl
> > use strict;
> > use warnings;
> > 
> > MAIN:
> > {
> >   open my $fh => 'GET http://www.perl.com |' or die "could not open url";
> >   while(<$fh>){
> >     print $_;
> >   }
> >   exit 0;
> > }
> 
> I see this and kind of go 'ew'.  Perl has it's own native
> web-reading capabilities, what you are doing is forking a shell
> which is running another perl process to read a web page!  GET is
> part of the LWP package, which provides some simply ways of getting
> a web page.

How about:

#!/usr/bin/perl -w
use strict;
use LWP::Simple;

my $url = (@ARGV == 1 && $ARGV[0]) || die "Usage: $0 URL\n";
my $page = get($url) || die "$0: cannot get $url\n";
open(FILE, '<', \$page) or die "$0: cannot open string as file\n";
print while <FILE>;
close(FILE);

-- 
Eric C. Cooper          e c c @ c m u . e d u



More information about the wplug mailing list