Hello, I have a file like below that contains datewise value for every hour for 2 locations. I need to add the value for the same hours for ServerA and ServerB. Using Hashes, I am able to add the server value per hour. But cannot pass it to a table. I am selecting "Loc" via a dropdown to use a switch to select the data.

Input File:

Loc Date Hour Server Val USA 1-Sep 00 ServerA 10 USA 1-Sep 00 ServerB 11 USA 1-Sep 01 ServerA 09 USA 1-Sep 01 ServerB 10 USA 1-Sep 02 ServerA 07 USA 1-Sep 02 ServerB 08 USA 2-Sep 00 ServerA 05 USA 2-Sep 00 ServerB 06 USA 2-Sep 01 ServerA 07 USA 2-Sep 01 ServerB 07 USA 2-Sep 02 ServerA 05 USA 2-Sep 02 ServerB 06 EUROPE 1-Sep 00 ServerA 10 EUROPE 1-Sep 00 ServerB 11 EUROPE 1-Sep 01 ServerA 09 EUROPE 1-Sep 01 ServerB 10 EUROPE 1-Sep 02 ServerA 07 EUROPE 1-Sep 02 ServerB 08 EUROPE 2-Sep 00 ServerA 05 EUROPE 2-Sep 00 ServerB 06 EUROPE 2-Sep 01 ServerA 07 EUROPE 2-Sep 01 ServerB 07 EUROPE 2-Sep 02 ServerA 05 EUROPE 2-Sep 02 ServerB 06

OUTPUT in HTML Table

Hours/Date 00 01 02 03 04 05 06 07 08 09 + 10 11 12 13 14 15 16 17 18 19 20 + 21 22 23 Sep-1 21 19 15 Sep-2 11 14 11

Code is as below

while(<DATA>) { ($keys, $date, $token, $server, $hour, $peak)= split; @th = $date; #$res{$key}{$server}->{REGION}++; #$res{$key}{$user}->{QUANTITY}++; if ($keys eq $filename){ switch($filename){ case "USA" {$res{$keys}{$date}->{DATE};$res{DATE}{ +$hour}->{PEAK}+=$peak;$flag=1} case "EUROPE" {$res{$date}{$hour}->{PEAK}+=$peak;$ +flag=1} else { print "previous case not true" } } } } if ($flag){ pgm_fil(); } my $tablecontent; sub pgm_fil{ my $q = new CGI; $q->header; $q->start_html(); print "<table border=1>"; my $tablecontent=[$q->th(['Date/Hours', '01', '02', '03', +'04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15 +', '16', '17', '18', '19', '20', '21', '22', '23'])]; print "<tr><td>Date/Hours</td>"; foreach $datea(@th){ print "<td>$datea</td>"; } foreach my $key (sort {$a<=>$b} keys %res){ foreach my $user (keys %{$res{$key}}){ foreach my $user1 (keys %{$res{$key}{$user}}){ my @hashval = $res{$key}{$user}{$user1}; foreach my $hashval( @hashval){ print "<tr><td>$user</td><td>$hashval[$_]</td></tr +>"; push @$tablecontent,$q->td([$date,$hashval[$_] ]); } } } } print "</tr></table>"; print $q->table( { border => 1, -width => '50%', -align=>' +left'}, $q->Tr( $tablecontent), ); }

In reply to Perl help with html cgi table by vkknava

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.