AnyDat...Ltable(3pm)

πŸ’– NAME πŸ’–

HTMLtable β€” it's giving tied hash and DBI/SQL access to HTML tables, bestie πŸŽ€

This is the page for AnyDat...Ltable(3pm) from the User Contributed Perl Documentation, and no, the name isn't a typo, that's literally how the header truncates it. We move πŸ’…


✨ SYNOPSIS ✨

Okay so first vibe: the tied hash era πŸ¦‹

use AnyData;
my $table = adHash( 'HTMLtable', $filename );
while (my $row = each %$table) {
   print $row->{name},"\n" if $row->{country} =~ /us|mx|ca/;
}
# ... other tied hash operations

OR β€” plot twist, we're doing SQL now πŸ‘‘

use DBI
my $dbh = DBI->connect('dbi:AnyData:');
$dbh->func('table1','HTMLtable', $filename,'ad_catalog');
my $hits = $dbh->selectall_arrayref( qq{
    SELECT name FROM table1 WHERE country = 'us'
});
# ... other DBI/SQL operations

(Yes, use DBI has no semicolon in there. That's not me being sloppy, that's canon, don't come for me 😭)


🌸 DESCRIPTION 🌸

So like, this module lets you treat the data inside an HTML table as a tied hash (that's the AnyData.pm route, periodt) or as a DBI/SQL accessible database (that's the DBD::AnyData.pm route, slay). And both the tiedhash and the DBI interfaces let you read, modify, and create HTML tables from perl data β€” from local files or remote files, either way, we're covered 🫢

Before you get too excited: the module requires that CGI, HTML::Parser and HTML::TableExtract are installed. No cap. Install them or nothing works πŸ’€

πŸ¦‹ The reading era

When you're reading an HTML table, this module is essentially just a pass through to Matt Sisk's excellent HTML::TableExtract module. Iconic behaviour honestly, we're just the messenger 🧚

If you don't specify any flags in the adTie() or ad_catalog() calls, then TableExtract gets called with depth=0 and count=0. In other words (literally in other words): it finds the first row of the first table and treats that as the column names for the entire table. Vibe check passed βœ…

If you do pass a flag for 'cols' (that's column names, iykyk) in your adTie() or ad_catalog() calls, then that list of column names gets passed to TableExtract as a headers parameter. Cute πŸ’…

And if you specify flags for headers, depth, or count? Those get passed directly to TableExtract. No middleman, no drama.

πŸŽ€ The exporting era

When exporting to an HTMLtable, you may pass flags to specify properties of:

  • the whole table β€” that's table_flags πŸ‘‘
  • the top row containing the column names β€” that's top_row_flags ✨
  • the data rows β€” that's data_row_flags πŸ“

These flags follow the syntax of CGI.pm table constructors, e.g.:

print adExport( $table, 'HTMLtable', {
    table_flags    => {Border=>3,bgColor=>'blue'};
    top_row_flags  => {bgColor=>'red'};
    data_row_flags => {valign='top'};
});

Now the defaults, because defaults are the main character here:

  • The table_flags will default to {Border=>1,bgColor=>'white'} if none are specified.
  • The top_row_flags will default to {bgColor=>'#c0c0c0'} if none are specified;
  • The data_row_flags will be empty if none are specified.

In other words (again, in other words, we love a recap): if no flags are specified the table will print out with a border of 1, the column headings in gray, and the data rows in white. Aesthetic, honestly 🀍

CAUTION: This module will *not* preserve anything in the html file except the selected table so if your file contains more than the selected table, you will want to use adTie() or $dbh->func(...,'ad_import') to read the table and then adExport() or $dbh->func(...,'ad_export') to write the table to a different file. When using the HTMLtable format, this is the only way to preserve changes to the data, the adTie() command will *not* write to a file. Bestie please read this part twice, I'm begging πŸ™ˆ

copyright 2000, Jeff Zucker <jeff@vpservices.com> all rights reserved


And that's the whole page, bestie β€” no crumbs left behind πŸ’– This was AnyDat...Ltable(3pm), hanging out in the User Contributed Perl Documentation section, brought to you by perl v5.36.0 and dated 2023-08-06. Go forth and tie those hashes, you absolute legend πŸ‘‘βœ¨

πŸ“¦ where this page comes from