jdlev,
Dumping a data structure is primarily used to help visualize your data or to serialize it. I would not use Data::Dumper to store things to a database unless I was trying to serialize a data structure. In other words, not if I intended for individual parts to be able to be searched after.

It is no secret that I really do not coding anything web related so the following is probably the wrong way to do it, but it makes your intent a whole lot more clear:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use WWW::Mechanize; use HTML::TableContentParser; use HTML::TokeParser::Simple; my $url= "http://www.servpro.com/locator/lookup.asp?stname=Alabama&sta +te=AL"; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->get($url); my $table = HTML::TableContentParser->new()->parse($mech->content); for my $t (@$table) { next if ! want_table($t); my $cell = $t->{rows}[0]{cells}[0]{data}; my $p = HTML::TokeParser::Simple->new(\$cell); my ($name, $owner, $phone, $fax, $website); my $rec = {}; my %seq = (1 => 'name', 3 => 'name', 4 => 'owner', 5 => 'phone', 6 + => 'fax'); my $cnt; while (my $token = $p->get_token) { next if ! $token->is_text && ! $token->is_start_tag('a'); ++$cnt; my $field = $seq{$cnt}; if ($field) { $rec->{$field} .= $token->as_is if $token->is_text; next; } if ($token->is_start_tag('a')) { $rec->{website} = $token->return_attr('href'); last; } } print Dumper($rec); } sub want_table { my ($t) = @_; return if ! $t->{class}; return if $t->{class} ne 'smalltext'; return if @{$t->{rows}} > 2; return 1; }

You can replace the call to Dumper with storing a record in the database. $rec->{owner} will contain the owner information and $rec->{website} will contain the url to the website, etc, etc.

Cheers - L~R


In reply to Re: PERL HTML::TableExtractor by Limbic~Region
in thread PERL HTML::TableExtractor by jdlev

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.