Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

AoAoA to Text (or HTML table to text)

by PodMaster (Abbot)
on Feb 07, 2003 at 12:59 UTC ( [id://233456]=perlquestion: print w/replies, xml ) Need Help??

PodMaster has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a tough time finding a module (or code) which would turn a HTML table into text (wrapping and all).

Or a module which would neatly format/wrap an AoAoA something like this:

my @Table = ( [ ["0123456","bar","0" ], ["Let's talk about these excellent numbers"], ["Bah bar" ], [ '0123456' ] ] ); use Text::WrapAoAoA; print wrapit( { colsep => ' ', colwrap => [ 4, 10], asonetable => 1, },@Table); print wrapit( { colsep => ' ', colwrap => [ 4, 10], asonetable => 0, },@Table); __END__ # results if wrapping for 1st column was 4 # and for 2nd column was 10 # with a separation between them of 1 space 0123- Let's talk 456 about these bar excellent 0 numbers Bah bar 0123456 # or even this, given the option 0123- Let's talk 456 about these excellent numbers bar Bah bar 0 0123456
Now I could write something, and probably will eventually, but i'm really dying for a canned solution (this isn't on my to-do list yet, and i'd rather it don't end up there).

update: removed a stray }


MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: AoAoA to Text (or HTML table to text)
by steves (Curate) on Feb 07, 2003 at 13:19 UTC
      Thanks a lot, that will do very nicely (i'm a little suprised I missed it).
      #!/usr/bin/perl use strict; use warnings; use Text::Table; print "==== Monks I think rock! ====\n\n"; my $tB = Text::Table->new( \'[ ', { title => 'Name', align => 'left', }, \" | ", #separator { title => ' ', align => 'right', }, \' ]', ); $tB->load( [ steves => 'rocks plenty, found Text::Table'], [ 'Anno Siegel' => 'rocks plenty, after all he wrote Text::Table'] +, ); print $tB->title(); print $tB->rule('#','#'); print $tB->body(0); # bugger, a buG # print $tB->title_rule('.'); print $tB->rule(); print $tB->body(1); print $tB->body_rule('.'); print $tB->rule(); # this one ought to be called align # and part of the package print Text::Aligner::align( right => ( ' ' x ( $tB->width() - length '... and many more ' ) ) . '... and many more ' ),"\n"; __END__ ==== Monks I think rock! ==== [ Name | ] ############################################################## [ steves | rocks plenty, found Text::Table ] [ | ] [ Anno Siegel | rocks plenty, after all he wrote Text::Table ] [.............|..............................................] [ | ] ... and many more
      update: I realized Anno is probably not a monk, oh well ;)


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: AoAoA to Text (or HTML table to text)
by CountZero (Bishop) on Feb 07, 2003 at 16:49 UTC

    Would Data::Dumper be a step in the good direction? And perhaps capturing its output and slightly re-formatting it?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      How would that work? I'll stick with a variation on Re: Re: AoAoA to Text (or HTML table to text) thank you very much.


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: AoAoA to Text (or HTML table to text)
by mattr (Curate) on Feb 09, 2003 at 10:32 UTC
    I just happened to have done some module searches a couple days ago in this area and was thinking how nice if there was a thread to post it too.. For some reason I have more trouble with the new (beautiful but catches everything!) search.cpan.org engine.

    (I think it would really be useful to have a list of CPAN modules answering domain-specific questions like this one, with people's experiences with them. Or maybe people could take it upon themselves and get added to faq or somewhere?.. Questions. In other words, what is the best way to resolve the problem with many differently named modules, how to find the right one? Plus, how to leverage the jillions of man-hours that have already gone into solving these questions by someone somewhere in the Perl Community? Cpan directory is not up to date/no experience or conversation like Perlmonks has. Ideas welcome. )

    Short answer - Text::Table, Text::FormatTable, Data::ShowTable.. then some other quick HTML ones in list below.

    Long answer..

    Text::Table I think I also remember.. see above. I wanted HTML so didn't follow it up.

    Text::FormatTable - text tables

    Data::ShowTable - lots of neat things to show tables from databases or subroutines. heavy,text or html

    HTML::TableLayout - java-like oo table maker,widgets. old(1998) and docs sometimes wrong it admits, eek!

    HTML::STable - simple table, actually really involved, inserting. Anyone with experience about using this module please post. also see: www.oocgi.com/doc_table.pl

    HTML::HashTable - quickly print hash as a sorted html table, sounds neat.

    HTML::Table - the standard, can do addrow addcol. I've used it in a HTML timesheet system for a 30 person company, about 10 cols by 50 rows and it was nice.

    HTML::QuickTable - looks nice, has auto nonnulling, font face, width and other html things. sorts hash by key.
    I'm probably going to use this for my current need which is to easily print things out for a management interface to a new search engine module I just made (Eye::Cats, not on CPAN, a directory match thingie much like Yahoo's). Short 'n sweet it says, about to try it today.

      I like this idea. I think CPAN would be even better if modules had a FAQ-oriented cross-reference and some way for users to add reviews and usage comments.

Re: AoAoA to Text (or HTML table to text)
by Anonymous Monk on Nov 12, 2004 at 16:07 UTC
    If you have questions about HTML::STable.pm, you can contact module owner at seyhan@rcn.com. You can also find detailed info in www.oocgi.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://233456]
Approved by bronto
Front-paged by toma
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-03-29 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found