vkknava has asked for the wisdom of the Perl Monks concerning the following question:
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), ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl help with html cgi table
by hippo (Archbishop) on May 17, 2015 at 12:08 UTC | |
by vkknava (Novice) on May 17, 2015 at 12:42 UTC | |
by hippo (Archbishop) on May 17, 2015 at 15:10 UTC | |
|
Re: Perl help with html cgi table
by kcott (Archbishop) on May 17, 2015 at 13:10 UTC |