in reply to Re^2: Foreach Array and Html table extract
in thread Foreach Array and Html table extract

Why don't you provide an updated snippet of code for us to play with, and some sample HTML that results in the error. Just wrap the HTML in code tags. It's easier to debug an error that we can easily reproduce.

Also, you may want to use the 'debug' method from HTML::TableExtract to inspect the assertions your code makes about the state of affairs immediately before the call to 'rows'.


Dave

  • Comment on Re^3: Foreach Array and Html table extract

Replies are listed 'Best First'.
Re^4: Foreach Array and Html table extract
by Anonymous Monk on Aug 14, 2012 at 20:47 UTC

    The code I'm sending the command prompt is the following: <\p>

    #!/usr/bin/perl use 5.014; # so push/pop/etc work on scalars (experimental) use strict; use warnings; use LWP::Simple 'get'; use HTML::TableExtract; my $file = 'C:\Payout Policy Paper\Data\urllist.csv'; open (FH, "< $file") or die "Can't open $file for read: $!"; my @lines = <FH>; close FH or die "Cannot close $file: $!"; print @lines; foreach my $line (@lines) { my $te = HTML::TableExtract->new( headers => [ 'Purchased','Average','Publicly','May'], slice_columns => 0,keep_html => 0,br_translate => 0 ); $te->parse($line); my $table = $te->first_table_found; my $file = "testout.csv"; open (F,">", $file); for my $row ($table->rows) { print F join('^', @$row), "\n"; } close (F); }

    If I'm correctly understanding your suggestion you can find an example of the html I am analyzing at:

     http://www.sec.gov/Archives/edgar/data/826083/000082608312000011/dellq1fy1310q.htm

      Christoforo is correct (below): You're never actually fetching the URL. LWP::Simple's "get" is never invoked. Even if you're reading the table from a file, you probably shouldn't be parsing it "line by line". Slurp the file into a scalar and parse the whole thing.


      Dave