in reply to Perl help with html cgi table

The RHS of

                    my @hashval = $res{$key}{$user}{$user1};

doesn't look much like an array to me. Perhaps this is (one place) where you are going wrong? It is however rather hard to tell given the overall poor shape which this code is in. If you tidy it up you might be better situated to do some debugging.

Once you've done that and have posted some sample code which compiles (the OP sample does not) we stand a better chance of helping you.

Replies are listed 'Best First'.
Re^2: Perl help with html cgi table
by vkknava (Novice) on May 17, 2015 at 12:42 UTC

    Hi,

    Thanks for the response. I am beginner, so very little knowledge of the advanced stuffs to reduce the coding complexity. May be the below code will give a better picture.

    my $filename = param('textcontent'); print "<br><br><br>"; print "The Location you have selected is: $filename"; print "<br><br><br>"; my $k; my $i=0;my $file;my @argv;my %res;my $key;my $date, my +$token, my $server, my $hour, my $peak;my $flag = 0;my $tablecontent; +my @th; open(DATA, "../cgi-bin/lic.txt") || die("Could not open file!" +); while(<DATA>) { ($key, $date, $token, $server, $hour, $peak)= split; if ($key eq $filename){ switch($filename){ case "EMEA" {$res{$date}{$hour}->{PEAK}+=$peak;$fl +ag=1} case "APAC" {$res{$date}{$hour}->{PEAK}+=$peak;$fl +ag=1} else { print "previous case not true" } } } } if ($flag){ pgm_fil(); } sub pgm_fil{ my $q = new CGI; $q->header; $q->start_html(); my $tablecontent=[$q->th(['Date/Hours','00', '01', '02', ' +03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14' +, '15', '16', '17', '18', '19', '20', '21', '22', '23'])]; foreach my $key (sort {$a<=>$b} keys %res){ foreach my $user (keys %{$res{$key}}){ foreach my $user1 (keys %{$res{$key}{$user}}){ push @$tablecontent,$q->td([$key,$res{$key}{$u +ser}{$user1}]); } } } print $q->table( { border => 1, -width => '50%', -align=>' +left'}, $q->Tr( $tablecontent), ); }

      Even though the indenting is much improved in this second example, I have to tell you that it still doesn't compile. Here's what I see with v5.14.3:

      $ perl -cw 1126889.pl Unquoted string "case" may clash with future reserved word at 1126889. +pl line 12. String found where operator expected at 1126889.pl line 12, near "case + "EMEA"" (Do you need to predeclare case?) Unquoted string "case" may clash with future reserved word at 1126889. +pl line 13. String found where operator expected at 1126889.pl line 13, near "case + "APAC"" (Do you need to predeclare case?) "my" variable $q masks earlier declaration in same statement at 112688 +9.pl line 23. "my" variable $q masks earlier declaration in same scope at 1126889.pl + line 24. "my" variable $tablecontent masks earlier declaration in same scope at + 1126889.pl line 25. syntax error at 1126889.pl line 11, near "){" syntax error at 1126889.pl line 12, near "}->" syntax error at 1126889.pl line 12, near "+=" syntax error at 1126889.pl line 12, near "1}" syntax error at 1126889.pl line 13, near "1}" syntax error at 1126889.pl line 36, near "}" 1126889.pl had compilation errors.

      Start by fixing the syntax errors and (as already suggested above) replacing select and case with something else. As you say you are a beginner try using something simple and intuitive such as

      if ('EMEA' eq $filename || 'APAC' eq $filename) { $res{$date}{$hour}->{PEAK} += $peak; $flag = 1; } else { print "previous case not true"; }

      instead. Note that this is not to suggest that $res{$date}{$hour}->{PEAK} += $peak; is the correct statement at that point but that's one step farther down the line. Try compiling the code samples before you post them. If you can post code which compiles then we'll at least have some idea where you are headed.