Slide 13.17: lynx: the Web text browser (cont.)
  Slide 14.1: Oracle database management systems
  Home


Demonstration of Using lynx


The following demonstration shows how to find the current temperature of the location by giving the zip code.




 

The program FindTemp.pl performs the following tasks:
  1. loads the Yahoo! Weather Page,
  2. uses the Unix command grep to find the line containing the temperature and put the line into the file named temp, and
  3. reads the file temp and uses the Perl pattern matching to find the temperature.

 ~wenchen/public_html/cgi-bin/handheld/wml/FindTemp.pl 

#!/usr/bin/perl
#
# This script must be located in the directory of /cgi-bin .
#

# Send Content-type.
print "Content-type: text/vnd.wap.wml \n\n";

# Send WML header information.
print "<?xml version=\"1.0\"?>\n";
print "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\""
   . " \"http://www.wapforum.org/DTD/wml_1.2.xml\">\n";

# Retrieve Web argument values.
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value =~ s/~!/ ~!/g;
  $FORM{$name} = $value;
}

print <<EndofWML;
<wml>
 <card>
  <p><br />
   <b>The temperature is 
EndofWML

$FORM{zipcode} =~ s/.*?(\d{5}).*/$1/;
$URL = "xml.weather.yahoo.com/forecastrss\?p=" . $FORM{zipcode};
system ( "lynx -dump $URL | grep ' F<p />' > temp" );

open   ( fh, "< temp" );
sysread( fh, $temp, 64 );
close  ( fh );

$temp =~ s/.*? (\S*?) F.*/$1/;
print  ( "<i>$temp</i>° F" );

print <<EndofWML;
  </b></p>
 </card>
</wml>
EndofWML