please help me to check why my code does not display the table in this format. Really appreciated ur zen time :)

Persons Absences

table data

Replacement Persons

table data

Room Changes

table data

#!/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 "<HTML><head><title>My Learning Page</title></head>"; print OUT "<h2><font color=#ffffff</font>My Home Page</h2>"; print OUT "<h2>Bulletin Date $date $time</h2></style>"; print OUT "<body bgcolor=#002b46>"; 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 "<h3>$key</h3>\n"; print OUT "<table border = 1 width = 1000 bordercolor=#e0e +0e0 cellpadding = 5 align=left>"; #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=#ff +ffff"; print OUT "<$td $bg align = left>$col[$j]"}; }; }; }; print OUT "</table>"; print OUT "</body>"; print OUT "\n</HTML>\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 m +odule 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 . $dtdlim +tr . $YEAR); my $realTime=($TIME); return $realDate, $realTime; }
Nirvana is Now or Never

In reply to Re^2: split the text file to multiple arrays by mhoang
in thread split the text file to multiple arrays by mhoang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.