Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Text::Table formatting with HTML

by jeffa (Bishop)
on Jul 10, 2015 at 20:57 UTC ( [id://1134260]=note: print w/replies, xml ) Need Help??


in reply to Text::Table formatting with HTML

You could try parsing the textual output from Text::Table but if you are the one controlling the program, then you already have the data you want to wrap into an HTML table. From the Text::Table docs:

use Text::Table; my $tb = Text::Table->new( "Planet", "Radius\nkm", "Density\ng/cm^3" ); $tb->load( [ "Mercury", 2360, 3.7 ], [ "Venus", 6110, 5.1 ], [ "Earth", 6378, 5.52 ], [ "Jupiter", 71030, 1.3 ], ); print $tb;

If you already have the data in memory, then you can instead try something like so (using my shiny new Spreadsheet::HTML)

use Spreadsheet::HTML qw( generate ); my @data =( ["Planet", "Radius\nkm", "Density\ng/cm^3"], [ "Mercury", 2360, 3.7 ], [ "Venus", 6110, 5.1 ], [ "Earth", 6378, 5.52 ], [ "Jupiter", 71030, 1.3 ], ); print generate( data => \@data );

Spreadsheet::HTML can attempt to load data from a number of file formats but plain old text is not one of them because there are very many different possibilities. It is certainly possible, but likely at the expense of making my API more complex. Hope this helps! :)

P.S. I just released v0.36 which fixes a bug introduced in v0.34 in which the animate feature was breaking. This new release also features the ability to produce Handsontable tables, which are extremely slick Excel-like data grids. Very nice stuff.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Text::Table formatting with HTML
by yunglean808 (Novice) on Jul 13, 2015 at 17:47 UTC
    Thank you so much this helped a ton and was exactly what I was looking for!!!

      You are welcome. I have this sort of passion for HTML tables. :)

      If you are processing very large tables then you would be much better off printing out your own tags or even better, using a templating solution like Template:

      use strict; use warnings; use Template; my @data =( ["Planet", "Radius\nkm", "Density\ng/cm^3"], [ "Mercury", 2360, 3.7 ], [ "Venus", 6110, 5.1 ], [ "Earth", 6378, 5.52 ], [ "Jupiter", 71030, 1.3 ], ); my $tmpl = '<table>[% FOREACH row = rows %] <tr>[% FOREACH cell = row %] <td>[% cell %]</td>[% END %] </tr>[% END %] </table> '; my $table = Template->new; my $html = ''; $table->process( \$tmpl, { rows => \@data }, \$html ) or warn $table-> +error, $/; print $html;

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1134260]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found