Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


A Simple Goal

August 9, 1999

Let's refresh -- the Smallville Gazette is a modest newspaper which is "published" by a CGI script that inserts dynamic content into a pre-baked shell, not unlike pouring filling into a store bought pie crust. We began last month by featuring the current date in the Gazette's banner.

This month, as the Gazette evolves at this frightening pace, we're even more ambitious: beyond the date, we want to add the current temperature. Such real-time data lends a true sense of timeliness, and more importantly, illustrates the use of the LWP::Simple module.


Recall that the HTML for the Gazette template contained a placeholder for the date, which our Perl script used as a marker for a search-and-replace operation to insert the live date. We can expand that section of HTML to include a placeholder for the current temperature, as well -- and we'll also use HTML comment tags as placeholders now rather than visible text as we did last month (for illustrative purposes).

Excerpt from smallville.html, the web template for the Smallville Gazette.
<div align="center">
 <p>
  <font face="Verdana, sans-serif">
  <b><!--INSERT DATE HERE--><br>
     Current temperature: 
     <!--INSERT WEATHER HERE--></b></font>
 </p>
</div>

The original smallville.cgi Perl script simply read the entire smallville.html file and substituted the live date for the "INSERT DATE HERE" placeholder, using a Perl substitution:

Excerpt from smallville.cgi, substituting the live date for the date placeholder.
#determine current date
($sec,$min,$hour,$mday,
 $mon,$year,$wday,$yday,$isdst)=localtime(time);
$curDay=(Sunday,Monday,Tuesday,Wednesday,
         Thursday,Friday,Saturday)[$wday];
$curMonth=(January,February,March,April,
           May,June,July,August,September,
           October,November,December)[$mon];
$liveDate="$curDay, $curMonth $mday, ".($year+1900);

#search-and-replace on date
$resultPage=~s/<!--INSERT DATE HERE-->/$liveDate/g;

It should be clear, then, how we'll substitute the current temperature for the temperature placeholder. What isn't so clear is where we get the current temperature from?

The Perl You Need to Know
Simply, LWP::Simple


Up to => Home / Authoring / Languages / Perl / PerlfortheWeb




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers