#!/usr/bin/perl -- use strict; use warnings; { use CGI qw~ -nph :standard ~; my $BasePath = 'D:/finalfantasyinfo/community'; print header, start_html; MyNewsBoardApp::PrintSomeNews("$BasePath/boards/news.txt"); print end_html; exit; } package MyNewsBoardApp; use strict; use warnings; use POSIX; sub PrintSomeNews { my $NewsBoardFile = shift; my @NewsBoard = GetNewsBoard($NewsBoardFile); my $i = 0; while ( $i < 4 ) { print PostToHtml( GetNewsPost( $NewsBoard[$i][0] ) ); $i++; } } sub GetNewsBoard { use autodie qw' open close '; open my $NewsFh, shift; my @News = map { [ split /\|/, $_ ] } sort { $b <=> $a } <$NewsFh>; close $NewsFh; return @News; } sub GetNewsPost { use autodie qw' open close '; open my $NewsFh, shift; my $News = join '', $NewsFh; close $NewsFh; return split /\|/, $News; } sub PostToHtml { my (@News) = @_; my $ID = $News[3]; my $Time = POSIX::strftime( q!%H:%m %p on %B, %Y!, localtime( $News[3] ); $News[8] =~ s/\[(\/)?(b|u|i)\]/<$1$2>/gi; $News[8] =~ s~\[center](.*?)\[/center]~
$News[0]
Posted by: $News[1] at $Time
$News[8]
~; } __END__