#!/usr/bin/perl# RECENT_BOCODE: generate list of recent Stata SSC modules# C F Baum 9C08 with thanks to Paul Schinder, schinder@pobox.com# suggestions to update LWP module from that originally installed#print "Content-Type: text/html\n\n<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n";($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);$monb4=$mon;$year=$year+1900;$yrb4=$year;$dyb4=$mday;# monb4 is 12, not 11!if($mon==0) { $monb4=12; $yrb4=$year-1 }$curmo=$mon+1;$cmp=($curmo<10) ? "0" : "";$mp=($monb4<10) ? "0" : "";$dp=($dyb4<10) ? "0" : "";print "\n<html><title>Recent SSC-IDEAS Stata modules</title><body bgcolor=FFFEFE><h2>\n<A HREF=\"http://ideas.uqam.ca/ideas/data/bocbocode.html\">SSC-IDEAS</A> Stata modules <br>created or revised ";$currdt=$year.$cmp.$curmo.$dp.$dyb4;$prevdt=$yrb4.$mp.$monb4.$dp.$dyb4;print "$yrb4-$mp$monb4-$dp$dyb4 to $year-$cmp$curmo-$dp$dyb4</h2>\n\n<hr><pre>";$fs=0;# processing UNIX file, must split on \012 (not \n, since on MacPerl \n=\015)use LWP::Simple;$rdf=get 'ftp://ftp.bc.edu/pub/user/baum/RePEc/boc/bocode/bocodex.rdf';REDO:(@line)=split /\012/,$rdf;$line=@line;$desc="";$cre="";$rev="";@an={};foreach $i (@line) {	if ($i =~ m/^Title: (.+?): Stata (.+)/) { $name=$1; $desc=$2; }	if($i =~ /^Author-Name: (.+)/i ){push @an, $1;}	if($i =~ /^Creation-Date: (.+)/i ){$cre=$1;}	if($i =~ /^Revision-Date: (.+)/i ){$rev=$1;}	if($i =~ /^Handle: (.+)bocode:(.+)/i ) {		if($cre > $prevdt | $rev > $prevdt) {				print "<A HREF=\"http://ideas.uqam.ca/ideas/data/Softwares/bocbocode$2.html\">$name</A> $desc \n";				$nn=@an;				if($nn==2){print "Author: $an[1]\n"; } 				else {				for($i=1;$i<$nn-1;$i++){				print "Authors: $an[$i]   "; 					}					print "$an[$nn-1]\n";				}				if($rev>$cre){print "Revised: "; &fmt($rev); print "\n\n";}				else{print "Created: "; &fmt($cre); print "\n\n";} 				}			$cre="";			$rev="";			@an={};		}	}if($fs==0) {	$rdf = get 'ftp://ftp.bc.edu/pub/user/baum/RePEc/boc/bocode/bocodey.rdf';	$fs++;	goto REDO;	}print "\nEnd of recent additions and updates\n<hr>\n</PRE></body><html>";exit;sub fmt{        $_=@_[0];        $y=int($_/10000);        $m=int($_/100-$y*100);        $d=int($_-$y*10000-$m*100);        $mp=($m<10) ? "0" : "";        $dp=($d<10) ? "0" : "";        print "$y-$mp$m-$dp$d";}__END__