CGI and Perl

Listing 9.1. HTML returned by the Security APL Quote Server.

Code:

<HTML><HEAD>
 <TITLE>Security APL Quote Server</TITLE>
 <LINK REV="made" HREF="dhp@secapl.com"></HEAD>
 <CENTER>
 <NOBR>
 <A HREF=http://www.secapl.com/HOMELink>
 <IMG ALIGN=CENTER BORDER=0 SRC=http://www.secapl.com/qsImages/apl.gif
      ALT=" Security APL" HEIGHT=80 WIDTH=90></A>
 <B>
 <FONT SIZE=+3> S</FONT><FONT SIZE=+1>ecurity <FONT SIZE=+3>APL</FONT>
 <FONT SIZE=+3>Q</FONT>uote<FONT SIZE=+3>S</FONT>erver</FONT>
 </B>
 <HR WIDTH=600 SIZE=3 NOSHADE>
 <A HREF=http://www.secapl.com/ADLink>
 <IMG SRC=http://www.secapl.com/qsImages/barron.gif WIDTH=600
  HEIGHT=60 BORDER=0 ALT="Barrons" BORDER=0></A><BR>
 <HR WIDTH=600 SIZE=3 NOSHADE>
 <FONT SIZE=-1>
 <I>If your browser does not support tables, see the
 <A HREF=http://www.secapl.com/cgi-bin/qso><B>alternate Quote Server</B>
 </A> page.</I>
 </FONT>
 <P>
 <FORM METHOD="POST" ACTION="http://qs.secapl.com/cgi-bin/qso">
 <A HREF=http://www.secapl.com/secapl/quoteserver/ticks.html>
 <B>Ticker Symbols</A> : </B>
 <I>(Up to 5 tickers may be entered separated by spaces)</I><BR>
 <DD><INPUT NAME="tick" SIZE=30 MAXLENGTH=50>
 <B><FONT COLOR=0000FF><INPUT TYPE="submit" VALUE="  Get Quotes  ">
 </FONT></B></FORM>
 </CENTER><PRE>
 Symbol        : ADBE         Exchange    : NASDAQ
 Description   : ADOBE SYSTEMS INC
 Last Traded at: 35.1250      Date/Time   : Jul 05  1:01:34
 $ Change      : -0.1250      % Change    : -0.35
 Volume        : 330300       # of Trades : 251
 Bid           : 35.1250      Ask         : 35.2500
 Day Low       : 35.1250      Day High    : 35.7500
 52 Week Low   : 30.0000      52 Week High: 74.2500
 </PRE><CENTER>
 <A HREF="http://www.secapl.com/cgi-bin/edgarlink?'ADBE'">WWW hyperlinks
 </A> for the symbol ADBE are available
 including those from the
 <A HREF="http://town.hall.org/edgar/edgar.html">EDGAR Dissemination Project.</A>
 <HR>
 </CENTER><PRE>
 Symbol        : NSCP         Exchange    : NASDAQ
 Description   : NETSCAPE COMMUNICATIONS CP
 Last Traded at: 58.2500      Date/Time   : Jul 05  1:00:36
 $ Change      : -2.7500      % Change    : -4.51
 Volume        : 1000900      # of Trades : 803
 Bid           : 58.2500      Ask         : 59.0000
 Day Low       : 57.5000      Day High    : 60.2500
 52 Week Low   : 22.8750      52 Week High: 87.0000
 </PRE><CENTER>
 <A HREF="http://www.secapl.com/cgi-bin/edgarlink?'NSCP'">
 WWW hyperlinks</A> for the symbol NSCP are available
 including those from the
 <A HREF="http://town.hall.org/edgar/edgar.html">EDGAR Dissemination Project.</A>
 <HR>
 <P>
 <A HREF=http://www.secapl.com/secapl/quoteserver/mw.html>
 <FONT SIZE=+1><B>Market Watch</B></FONT></A> A Detailed Look at Market Activity
 <BR>
 <HR WIDTH=600 SIZE=3 NOSHADE>
 <A HREF=http://www.secapl.com/PAWLink>
 <IMG SRC=http://www.secapl.com/qsImages/qs.gif HEIGHT=30 WIDTH=600 BORDER=0
 ALT=></A><BR>
 <HR WIDTH=600 SIZE=3 NOSHADE>
 <B>
 <A HREF=http://www.secapl.com/PORTVUELink> PORTVUE</A> -
 <A HREF=http://www.secapl.com/NEWLink.html> WhatsNew</A> -
 <A HREF=http://www.secapl.com/PAWLink>PAWWS</A> -
 <FONT COLOR=777777>QuoteServer</FONT> -
 <A HREF=http://www.secapl.com/PODIUMLink>PODIUM</A> -
 <A HREF=http://www.secapl.com/SPONSORLink>Sponsored Sites</A>
 </B>
 <HR WIDTH=600 SIZE=1 NOSHADE>
 <FONT SIZE=+1>
 <B>
 <A HREF=http://www.secapl.com/secapl/quoteserver/search.html>Ticker Search</A> -
 <A HREF=http://www.secapl.com/secapl/qsq1.html>Questionnaire</A> -
 <A HREF=http://pawws.com/C_phtml/calculators.shtml>Financial Calculators</A>
 <HR WIDTH=100 SIZE=1 NOSHADE>
 <A HREF=http://www.secapl.com/NEWLink>What's New</A></B></FONT>
   -- Jun 4 1996: <A HREF=http://www.secapl.com/APLACCESSLink>Security APLACCESS
 </A> - electronic statement delivery via the Internet
 <BR>
 <HR WIDTH=600 SIZE=1 NOSHADE>
 <HR WIDTH=100 SIZE=1 NOSHADE>
 <FONT SIZE=-1>
 <A HREF=http://www.secapl.com/HOMELink>
 <B>Security APL</B></A>
 <I>and</I> <B><A HREF=http://www.secapl.com/NAQLink>
 North American Quotations, Inc.</B></A>
 <I>make no claims concerning the validity<BR>
 of the information provided herein, and will not be held liable
 for any use thereof.</I>
 </B>
 </FONT>
 </NOBR>
 <HR WIDTH=600 SIZE=3 NOSHADE>
 <I><A HREF=http://www.secapl.com/HOMELink>Security APL</A><BR>
 <A HREF=mailto:g.www@secapl.com>g.www@secapl.com</A></I>
 </CENTER></BODY></HTML>

To make our lives a lot easier, we won't attempt to submit the URL request by using raw socket calls--even though this can be done using Perl. Instead, let's use the WWW libraries available in the CPAN. Two important modules are HTTP::Request and HTTP::Response. Here, you'll use the HTTP::Request module to package up the URL request and the HTTP::Response module to handle the data coming back. The other module needed here is the LWP::UserAgent module. This powerful module acts as our communications vehicle. The code to retrieve data from the URL looks as simple as Listing 9.2.

The Security APL Quote Server, seen in Netscape.

Figure 9.1. The Security APL Quote Server, seen in Netscape.

by BrainBellupdated
Advertisement: