0

I think I've got the gist of creating a table using Perl's PDF::Report and PDF::Report::Table, but am having difficulty seeing what the 2-dimensional array @data would look like.

The documentation says it's a 2-dimensional array, but the example on CPAN just shows an array of arrays test1, test2, and so on, rather than the example showing data and formatting like $padding $bgcolor_odd, and so on.

Here's what I've done so far:

$main_rpt_path = "/home/ics/work/rpts/interim/mtr_prebill.rpt";

$main_rpt_pdf = 
  new PDF::Report('PageSize' => 'letter', 'PageOrientation' => 'Landscape',);

$main_rpt_tbl_wrt = 
  PDF::Report::Table->new($main_rpt_pdf);

Obviously, I can't pass a one dimensional array, but I have searched for examples and can only find the one in CPAN search.

Edit:

Here is how I am trying to call addTable:

$main_rpt_tbl_wrt->addTable(build_table_writer_array($pt_column_headers_ref, undef));
.
.
.

sub build_table_writer_array
# $data -- an array ref of data
# $format -- an array ref of formatting
#
# returns an array ref of a 2d array.
#

{
    my ($data, $format) = @_;

    my $out_data_table = undef;

    my @format_array = (10, 10, 0xFFFFFF, 0xFFFFCC);

    $out_data_table = [[@$data],];

    return $out_data_table;
}

and here is the error I'm getting.

Use of uninitialized value in subtraction (-) at /usr/local/share/perl5/PDF/Report/Table.pm line 88.
 at /usr/local/share/perl5/PDF/Report/Table.pm line 88

I cannot figure out what addTable wants for data. That is I am wondering where the formatting is supposed to go.

Edit:

It appears the addData call should look like

$main_rpt_tbl_wrt->addTable(build_table_writer_array($pt_column_headers_ref), 10,10,xFFFFFF, 0xFFFFCC);

not the way I've indicated.

Community
  • 1
  • 1
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
  • 1
    An array of arrays is by definition a 2D Array.I don't understand the question. They gave an example for the input: `my $some_data =[ ["test1", "test2", "test3"], ["test4", "test5", "test6"], ["test7", "test8", "test9"], ];$table_writer->addTable($some_data);` – Mattan Aug 10 '13 at 16:17
  • Yes, my confusion is where does the formatting go? Does it go in the second array or bound to each element of each array? – octopusgrabbus Aug 10 '13 at 16:28

1 Answers1

2

This looks like a bug in the module. I tried running the example code in the SYNOPSIS, and I got the same error you get. The module has no real tests, so it is no surprise that there would be bugs. You can report it on CPAN.

The POD has bugs, too.

You increase your chances of getting it fixed if you look at the source code and fix it yourself with a patch.

toolic
  • 57,801
  • 17
  • 75
  • 117