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_flagswill default to{Border=>1,bgColor=>'white'}if none are specified. - The
top_row_flagswill default to{bgColor=>'#c0c0c0'}if none are specified; - The
data_row_flagswill 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 useadTie()or$dbh->func(...,'ad_import')to read the table and thenadExport()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, theadTie()command will *not* write to a file. Bestie please read this part twice, I'm begging π
π AUTHOR & COPYRIGHT π
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
- debian trixie: libanydata-perl 0.12-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libanydata-perl 0.12-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libanydata-perl 0.12-3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms