#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use File::stat;
use Time::localtime;
#testing
my $dest = "C:/Perl-Script/";
my ($date,$time) = &GetTodaysDate;
my $space = '1';
open OUT, ">C:/Perl-Script/Bulletin.html";
print OUT "
My Learning Page";
print OUT "My Home Page
";
print OUT "Bulletin Date $date $time
";
print OUT "";
my %hdata = &build_hash();
foreach my $key (sort keys %hdata) {
my @arrays = @{$hdata{$key}};
if (($key eq '"$Persons Absences?"')|| ($key eq '"$Replacement Persons?"')
|| ($key eq '"$Room Changes?"')){
print OUT "\n\n";
print OUT "$key
\n";
print OUT "";
#print " $key = $data{$key}[$i]\n"; #$i= 0 is the title of table
for my $i(1..$#arrays) {
my @col = split(/,/,$arrays[$i]);
for my $j (1..$#col) {
$col[$j] =~ s/"//g;
my $td = ($i==1 || $j==1)? "th" : "td";
my $bg = ($i==1)? "bgcolor=#e0e0e0" : "bgcolor=#ffffff";
print OUT "<$td $bg align = left>$col[$j]"};
};
};
};
print OUT "
";
print OUT "";
print OUT "\n\n";
close(OUT);
#---------------------------------------------------------------------------
# This subroutine split text file to number of arrays
# for data processing
# --------------------------------------------------------------------------
sub build_hash()
{
my @tables;
my %data;
my $last ='';
open my $ifh,'<',"C:/Perl-Script/Bulletin.txt";
while (my $line=<$ifh>) {
chomp $line;
if ( substr($line,0,2) eq '"$' || substr($line,0,1) eq '$') {
$last=$line;
push @tables,$line;
}
push @{$data{$last}},$line;
return (%data);
}
#---------------------------------------------------------------------------
# This subroutine gets the local date and time using Time::Localtime module and
# formats it into dd/mm/yyyy and HH:mm. Returns $realTime, $realDate
# --------------------------------------------------------------------------
sub GetTodaysDate($){
#For Testing
my $source = "C:/Perl-Script/NBulletn.txt";
my $target = "C:/Perl-Script/Bulletin.html";
my $text_timestamp = ctime(stat($source)->mtime);
my $html_timestamp = ctime(stat($target)->mtime);
my ($WDATE, $MONTH, $DAY, $TIME,$YEAR) = split(" ",$html_timestamp);
my $datelimtr = " ";
my $dtdlimtr = "/";
my $tmdlimtr = ":";
my $realDate=($WDATE . $datelimtr . $DAY .$dtdlimtr . $MONTH . $dtdlimtr . $YEAR);
my $realTime=($TIME);
return $realDate, $realTime;
}