#!/usr/bin/perl
use strict;
use warnings;
use Time::Piece;
# current date/time
my $t = localtime;
my $date = $t->wdayname.' '.$t->dmy('/');
my $time = $t->hms;
# input data
my $dest = "C:/Perl-Script/";
my %hdata = build_hash($dest."Bulletin.txt");
# output html
open OUT, ">". $dest."Bulletin.html" or die "$!";
print OUT qq(
My Learning Page
My Home Page
Bulletin Date $date $time
\n);
foreach my $key (sort keys %hdata) {
if (($key eq '"$Persons Absences?"')
|| ($key eq '"$Replacement Persons?"')
|| ($key eq '"$Room Changes?"')){
print OUT qq!$key
\n!;
my @arrays = @{$hdata{$key}};
for my $i (1..$#arrays) {
print OUT '';
my @col = split(/,/,$arrays[$i]);
for my $j (1..$#col) {
$col[$j] =~ s/"//g;
my $td = ($i==1)? "th" : "td";
print OUT qq!<$td align="left">$col[$j]$td>!;
};
print OUT "
\n";
};
print OUT "
\n";
};
}
print OUT "";
close OUT;
#-------------------------------------
# This subroutine split text file to
# number of arrays for data processing
# -------------------------------------
sub build_hash{
my $infile = shift;
my %data;
my $last ='';
open my $ifh,'<',$infile or die "$!";
while (my $line=<$ifh>) {
chomp $line;
if ( substr($line,0,2) eq '"$'
|| substr($line,0,1) eq '$') {
$last = $line;
}
push @{$data{$last}},$line;
}
close $ifh;
return %data;
}