#!/usr/bin/perl -w use strict; use Fcntl qw(:flock); use constant MONTHS => qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); use constant DATE_RX => qr#(\d+)/(\d+)/(\d+) at (\d\d:\d\d:\d\d)#; print "Content-type: text/html\n\n"; my $boarddir = './yabb/Boards'; my $boardurl = '/cgi-bin/yabb/YaBB.pl'; chdir $boarddir or die "Cannot chdir to $boarddir: $!"; my @files = do { opendir my $dir, "." or die ("Cannot open Boards directory $!"); grep /\.txt\z/, readdir $dir; }; sub parse_time { require HTTP::Date; return unless @_ == 4; my $time = "$_[1] ".(MONTHS)[$_[0]-1]." $_[2] $_[3] GMT"; return ($time, HTTP::Date::str2time($time)); } my @data; for my $file (@files) { open my $fh, "<", $file or die "Cannot open file $file: $!"; flock $fh, LOCK_SH; my ($board) = $file =~ /(\w+)\./; while (<$fh>) { my ($id, $name, $user, $email, $datetime) = split /\|/; my ($time, $utime) = parse_date($datetime =~ DATE_RX); push @data, [ $utime, $board, $id, $name, $time ] if defined $utime; } } my @link = @{ sort { $a->[0] <=> $b->[0] } @data)[0] || [] }; printf qq{
%s
was updated on %s
}, $boardurl, @link[1..4];