#!/usr/bin/perl
#!/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/Extra/";
my %hdata = build_hash($dest."Bulletin.txt");
# output html
open OUT, ">". $dest."Bulletin.html" or die "$!";
print OUT qq(
OLMC Bulletin
Daily Activities Report
Bulletin Date $date $time
);
foreach my $key (keys %hdata) {
if (($key eq '"$Person Absences?"')
|| ($key eq '"$Replacement Person?"')
|| ($key eq '"$Room Changes?"')){
my $h4 = $key;
$h4 =~ s/[\"\$\?]//g;
print OUT qq!
$h4
\n!;
my @arrays = @{$hdata{$key}};
for my $i (1..$#arrays) {
print OUT '
';
my @col = split(/,/,$arrays[$i]);
for my $j (0..$#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;
}