2008/05/16

The Labs.Com Issue_04_CGI
Last update 1999/02/20

TPJ: Issue_04_CGI

This is a collection of programs published by The Perl Journal. You can download all source-code also from TPJ: Programs.
Issue_04_CGI
1. get_weather
Download get_weather

 #!/usr/bin/perl 
 # From Issue #4 of The Perl Journal 
 use LWP::UserAgent; 
 use HTML::Parse; 
 use HTML::FormatText; 
 # options 
 $CITY = shift || 'BOS'; 
 $URL = 'http://www.nnic.noaa.gov/cgi-bin/netcast.do-it'; 
 $OPTIONS = 'city=on&area=Local+Forecast&match=Strong+Match&html=text+o\ 
 nly+format'; 
 $agent = new LWP::UserAgent; 
 $request = new HTTP::Request('GET',"$URL?state=$CITY&$OPTIONS"); 
 $response = $agent->request($request); 
 die "Couldn't get URL.  Status code = ",$response->code 
     unless $response->isSuccess; 
 $parse_tree = parse_html($response->content); 
 $formatter = new HTML::FormatText; 
 @lines = split("\n",$formatter->format($parse_tree)); 
 foreach (@lines) { 
     print $_,"\n" if /^\s*[-]+\w/../^\s*[-]+$/; 
 } 

Issue_04_CGI
2. More Samples on CGI

                                                                                                                                   

Last update 1999/02/20

All Rights Reserved - (C) 1997 - 2008 by The Labs.Com

Top of Page

The Labs.Com