Domanda

I'm trying to display a table with some information and I have this code for that:

print $q->start_html(-title => "user summary");

print $q->table({-border=>1},
                   $q->tr($q->th(["Info","Value"])),#header
                   $q->tr($q->td(["Date",$date_var])),#first row
                   $q->tr($q->td(["Uptime",$uptime])),#second row
                   $q->tr($q->td(["1 min",$avg_one])),#third row
                   $q->tr($q->td(["5 min",$avg_two])),#fourth row
                   $q->tr($q->td(["15 min",$avg_two])),#fifth row
                   );

but when I run it I get:

Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>user summary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
Undefined subroutine CGI::tr
 at ./index.cgi line 30

where ./index.cgi line 30 refer to this line print $q->table({-border=>1 and on the webpage I get 500 Internal Server Error

so any ideas?

È stato utile?

Soluzione

I think it is

$q->Tr(...)

rather than

$q->tr(...)

Altri suggerimenti

tr is a synonym of y, the translation operator. Use Tr for CGI's table row.

You've got the right answer (twice) already, but I just wanted to point you at the "Non-Standard HTML Shortcuts" section of the CGI documentation, which says:

A few HTML tags don't follow the standard pattern for various reasons.

comment() generates an HTML comment (). Call it like

print comment('here is my comment');

Because of conflicts with built-in Perl functions, the following functions begin with initial caps:

  • Select
  • Tr
  • Link
  • Delete
  • Accept
  • Sub

In addition, start_html(), end_html(), start_form(), end_form(), start_multipart_form() and all the fill-out form tags are special. See their respective sections.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top