in reply to How do I use CGI.pm methods in a loop

You don't seem to be calling the Tr function. Also, you seem to expect method calls to be expanded in double-quoted strings - which they aren't. Oh, and you're trying (unnecessarily) to quote characters with the wrong kind of slash.

while ($dy < 32) { if ($dow == 0 || $dow == 6) { $table_info .= $q->Tr({-align => 'left', -color => 'yellow'}, $q->th([$...])); } else { $table_info .= $q->Tr({-align => 'left'}, $q->th([$...])); } $dy++; }

With code like that I'd assume that you'd get a lot of syntax errors. Did you check the web server error log?

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: How do I use CGI.pm methods in a loop
by davidrw (Prior) on Jul 28, 2006 at 12:10 UTC
    To OP -- since all you're trying to do is make certain rows a different color, then you can have the code reflect that as well, making it easier to read and maintain:
    while ($dy < 32) { $table_info .= $q->Tr({ -align => 'left', ($dow == 0 || $dow == 6 ? (-color => 'yello +w') : () ), }, $q->th([$...]), ); $dy++; }
    Then from here, we can go even further and use map (and use "THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS" -- see CGI pod):
    print OUTPUT $q->table({-cellpadding => 3}, $q->Tr({-align => 'left'}, [ map { $q->Td( { ($dow == 0 || $dow == 6 ? (-color => 'yellow') : ( +)) }, [ ... ] ) } 0 .. 31 ]), );