It's quite easy to put together a routine that does output such a table. Be aware though, that this table doesn't have any fancy features you might expect from HTML tables. AxPoint has it's own format for generating tables.

Below is a routine that does output what the AxPoint docs want. It's not tested with AxPoint, however.

#!/usr/bin/perl use strict; use warnings; use List::Util qw/max sum/; $|++; # produces a layout of a table used in AxPoint # input: # $table_aref - reference to an array of arrays containing the eleme +nts # of the table # %options - additional (not compulsory) named parameters: # percent_size - reference to an array containg the size of the co +lumns # of the table (in percent of the total width) # [ will be calculated if not given ] # indent - string to use as indent for the different levels of the + layout # string will be used multiple times for deeper levels # # Assumptions: # - all rows of the table have the same length (amount of columns) # - if a percent_size array reference is given, the array has the +same length # as a row of the table. # # if any of these assumptions is wrong, the routine returns an empty + list # # normally returns an array of lines of the layouted table sub layout_table { my ($table_aref, %options) = @_; my @option_keys = qw/indent percent_size/; my ($indent, $percent_size_aref) = @options{@option_keys}; $indent = "\t" unless defined $indent; my $row_length = @{$table_aref->[0]}; for my $key (keys %options) { warn("Unrecognized option '$key' in 'layout_table'"), return unless grep { $key eq $_ } @option_keys; } if ($percent_size_aref) { # check length of percent_size return if @$percent_size_aref != $row_length; } else { # must calculate size of each column my @max_lengths = (0) x $row_length; for my $row (@$table_aref) { my $i = 0; @max_lengths = map { max($_, length $row->[$i++]) } @max_l +engths; } my $total_length = sum(@max_lengths); $percent_size_aref = [ map sprintf('%5.2f', 100*$_/$total_leng +th), @max_lengths ]; } my @result = ( '<table>' ); for my $row (@$table_aref) { return if $row_length != @$row; # check that all rows have sam +e no. columns push @result, $indent . '<row>'; for (my $i = 0; $i<$row_length; $i++) { my $p_size = $percent_size_aref->[$i]; push @result, $indent x 2 . qq/<col width="$p_size%">/; push @result, $indent x 3 . $row->[$i]; push @result, $indent x 2 . "</col>"; } push @result, $indent . '</row>' } push @result, '</table>'; return @result; } my @data; while (<DATA>) { push @data, [ split ]; } local $, = "\n"; print layout_table(\@data); print layout_table(\@data, percent_size => [50, 20, 20, 10] ); print layout_table(\@data, percent_size => [50, 20, 20, 10], indent => + ' ' ); print layout_table(\@data, perdent_size => [0.5, 0.2, 0.2, 0.1]); __DATA__ year income expense rest 2000 10 9 1 2001 20 13 7

-- Hofmator


In reply to Re: Perl AxPoint and HTML tables by Hofmator
in thread Perl AxPoint and HTML tables by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.