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

Dear friends, I'm trying to use HTML::Table to construct an output, and it is working quite well for me, except that I cannot seem to manipulate head rows very well.

my $table = new HTML::Table (
    -border => 1,
    -rules   => 'both',
    -spacing => 0,
    -padding => 3,
    -align   => 'CENTER',
    -style   => 'text-align: right;',
    -width   => '100%',
    -head    => $sth->{NAME},
    -data    => $data,
);

That -head accepts an array, which works well if only one row of headers is needed. But when I must use multiple rows, I can't figure out how to program it. I read the docs -- have no clue. Thanks in advance.

Replies are listed 'Best First'.
Re: HTML::Table multi-row head
by davis (Vicar) on Jan 06, 2005 at 14:00 UTC
    Update: This is piffle. Follow simonm's advice.
    You want an array reference, as used in the docs. They can be created using the square bracket notation thusly:
    my $array_ref = ["foo", "bar", "baz"];
    Note that $array_ref is a scalar. To use it in your context:
    my $table = new HTML::Table ( -border => 1, -rules => 'both', -spacing => 0, -padding => 3, -align => 'CENTER', -style => 'text-align: right;', -width => '100%', -head => [$sth->{NAME}, "foo", "bar", "baz", "whatever"], -data => $data, );

    davis
    It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
      I think that $sth->{NAME} is already an array reference.

      If you want multiple heading rows I think the OP will need to add them after the new() call:

      $table->addRow(@second_header); $table->setRowHead(-1);
        It does not work, however... Since I lack good imagination I tested that code by doing this:
        $table->addRow($sth->{NAME});
        $table->addRow($sth->{NAME});
        $table->setRowHead(-1);
        
        But my script suddenly failed to load. In the background two instances of perl.exe are running and the browser fails to load the table anymore.

        In a word, d'oh. You may ignore my demented ramblings.


        davis
        It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.