You can fiddle with $COLUMS to change the table row-width

use strict; use warnings; use XML::Simple; use Data::Dumper; # read __DATA__ file into $_ { $/ = undef; $_ = <DATA>; close DATA; } # use XML::Simple to read the table string my $ref = XMLin( $_ , NoAttr=>1 ); my $tr = $ref->{tr}; my @ARR; # flatten table structure into an array for my $row (keys @{$tr}){ my @X = values @{(values %{ $tr->[$row] })[0]}; push @ARR, @X; } # now we reformat the table my $COLUMNS = 2; my $counter = 0; my %S; for my $v (@ARR){ my $i=int($counter/$COLUMNS); my $j=int($counter % $COLUMNS); push @{$S{'tr'}->[$i]->{'td'}}, $v; ++$counter; } # We use XML::Simple to transform this stucture to an xml/html string my $xml = new XML::Simple (NoAttr=>1, RootName=>'table'); # convert Perl array ref into XML document my $new_table = $xml->XMLout(\%S); # now show the result print $new_table; __DATA__ <table style="width:100%"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> </table>

In reply to Re: Re-dimensioning an HTML table with Perl ? by FreeBeerReekingMonk
in thread Re-dimensioning an HTML table with Perl ? by TheDonald

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.