Posted on 2005-08-12 18:32:09-07 by techgeek
Is there any way to have a footer line?
NOTE: I dont know how to get the posting text below to maintain the fixed with text in the code blocks? Often when I use this module I will be displaying numeric data in the columns and will want the last row to be a totals row.

This code
$t = new Text::ASCIITable; $t->setCols("one",'two','three','four'); push @$t, ( "1" ) x 4; # Replaces $t->addrow(); push @$t, ( "2" ) x 4; # Replaces $t->addrow(); print $t; # Replaces print $t->draw();
looks like this

.=----+-----+-------+-----=. | one | two | three | four | |=----+-----+-------+-----=| | 1 | 1 | 1 | 1 | | 2 | 2 | 2 | 2 | '=----+-----+-------+-----='
but I want to be able to have a table kind of look like this

.=----+-----+-------+-----=. | one | two | three | four | |=----+-----+-------+-----=| | 1 | 1 | 1 | 1 | | 2 | 2 | 2 | 2 | |=----+-----+-------+-----=| | 3 | 3 | 3 | 3 | '=----+-----+-------+------'

Any ideas on how to do this?

I dont want the module to do the adding I just want to be able to have a extra rowLine added prior to my last row which will separate the rows above from the final (total) row.

I do not see directly how to do this easily within the module other than trying to generate a 2nd table just to do the last total line but this seems like it would be hard to insure the column widths matched the table above.

Some ideas or possible enhancements assuming the module cant do this already:
- A way to draw a RowLine not between every row but selectively?
Maybe as I am adding my rows prior to the last row I could run a new command that would essentially tell the module that I wanted to add a RowLine after the last defined row.
- Maybe a SetBotCols construct which could be done after all rows have been added and the module would add essentially a footer row

Of the two the first probably gives more flexibilty in that a selective added RowLine could be added when needed.

Just some thoughts?
Thanks, techgeek
Direct Responses: 906 | Write a response
Posted on 2005-08-17 08:47:47-07 by lunatics in response to 876
Re: Is there any way to have a footer line?
Hey, Thanks for the compliments, and thoughts! There is a dirty way to get what you want. If you turn on rowLines you could do this:
$t = new Text::ASCIITable({ drawRowLine => 1 }); $t->setCols("one",'two','three','four'); push @$t, (join("\n",( 1..2 ))) x 4; push @$t, ( '3', '3', '3', '3' ); print $t;
Maybe I will make this easier in a future update. Probably soon.. It was an good idea as an addition :) -- Håkon Nessjøen
Direct Responses: 908 | Write a response
Posted on 2005-08-17 18:14:59-07 by techgeek in response to 906
Re: Is there any way to have a footer line?
Nice, I didnt think about joining together all the column values except the last row and then pushing the columns as a row. I usually just push a row at a time but as you said for a work around this would be doable although as you mentioned might be a nice addition in the future.

Thanks for the suggestion!
techgeek
Direct Responses: 1107 | Write a response
Posted on 2005-10-02 04:33:16-07 by lunatics in response to 908
Re: Is there any way to have a footer line?
I just added a new feature in the upcoming version of Text::ASCIITable. The new subroutine is called addRowLine. And is documented as follows:
addRowLine([$row]) Will add a line after the current row. As an argument, you may specify after which row you want a line (first row is 1) or an array of row numbers. (HINT: If you want a line after every row, read about the drawRowLine option in setOptions()) Example without arguments: $t->addRow('one','two','three'); $t->addRowLine(); $t->addRow('one','two','three'); $t->addRow('one','two','three'); Example with argument: $t->addRow('one','two','three'); $t->addRow('one','two','three'); $t->addRow('one','two','three'); $t->addRow('one','two','three'); $t->addRowLine(1); # or multiple: $t->addRowLine([2,3]);
If you have any objections/ideas to this, please tell me, and I'll consider changing it :)
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.