Hero Zzyzzx has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone explain to me why this code snippet gets this error message? It works fine, but I don't like stuff going into my error logs that I'm not sure about. I've pored over the CGI.pm docs and I think my syntax is right.

Error Message
Odd number of elements in hash assignment at /XXXXXXX/browse.pl line 139.

Code that generates this error:
$bgcolor is a computed hex value, $cointype is just text. Obviously I'm using CGI.pm for output.

print $q->Tr({-bgcolor=>"#".$bgcolor.$bgcolor.$bgcolor,"align=\"left\" +"}, [$q->th({-colspan=>8,"class=\"typeheader\""},$cointype)]);

Replies are listed 'Best First'.
Re: Odd number of hash elements error_log entry
by japhy (Canon) on Apr 09, 2001 at 19:46 UTC
    The hash reference:
    { -bgcolor => "#" . $bgcolor . $bgcolor . $bgcolor, 'align="left"', }
    has a key, a value, and a key with no value. Perhaps you meant to do:
    { -bgcolor => "#" . $bgcolor . $bgcolor . $bgcolor, -align => 'left', }
    Likewise for your other hash reference.

    japhy -- Perl and Regex Hacker

      BINGO!!
      The strange thing was that it worked fine. I guess my syntax wasn't completely correct and I need to figure out CGI.pm a little more.

      Gracias, japhy!