[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Daily Fact Script



According to Jason Todd:
> 
> Can anyone suggest or point me towards This Day in History script? I'm 
> not looking for Random Text. I've seen sites that do this, but had no 
> luck finding a script. I'm just learning Perl now. I have the list of 
> facts. Right now, on the site, I have a page for each month that I post. 
> I want to make it more dynamic for the viewer (that's what I told my 
> boss) and less work for me. Thanks.
> 

This should be REALLY easy to program.  :-)  Let me help get you started.

#!perl
#
#	Standard Stuff.
#
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
	$mon += 1;
	$curDate = sprintf( "%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $mon, $mday, $year, $hour, $min, $sec );
#
#	Start up the HTML header stuff.
#
	$theReply = <<END_HTML;
Content-type:	text/html

<html>
<head>
<title>This Day In History!</title>
</head>


<body bgcolor=#ffffff text=#000000>
<font size=+6>History Lesson</font><p>
On this day in history,<br>
END_HTML
#
#	Get your facts
#
#	Records are laid out as:
#
#	mm/dd/yy:The Fact
#
	open( THEFILE, "history.dat" ) || die $!;
	@theFacts = <THEFILE>;
	close( THEFILE );
#
#	Clear off the end stuff.
#
	for( $i=0; $i<=$#theFacts; $i++ ){
		chomp( $theFacts[$i] );
#
#	Scan everything
#
		@theLine = split( /:/, $theFacts[$i] );
		$theDate = split( /\//, $theLine[0] );
		if( ($theDate[0] == $mon) && ($theDate[1] == $mday) && ($theDate[2] == $year) ){
			$theReply .= "$theLine[1] - $theLine[2]<br>";
			}
		}

	$theReply .= <<END_HTML;
</body>
</html>
END_HTML

	print $theReply;
	exit( 0 );

Ok, so I wrote the entire thing.  Anyway - if you want to
include the hour, minute, and seconds you will have to
change the separator from ":" to something else and modify
the part whic splits up the information.  Also you probably
want to put this all into a table since everything would
align if it were put into a table.  So there are a few
things left for you to do.  :-)


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch