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

Hello,

I am using code which accesses table data from a webpage. I have gotten the code to display the data values, but each data value is coming out on a separate line. Can someone enlighten me on how to get the 4 column values on one line (row) in this fashion:
a1, a2, a3, a4 b1, b2, b3, b4 . . .
I am also wondering if I can somehow 'grab' (save) the literal "Earnings Announcements for: Friday, May 2, 2003" which displays as a title above the table, since the date is crucial. Here is the code I have built so far:
#!/usr/bin/perl use warnings; use strict; use LWP::Simple; use HTML::TableExtract; my $url; $url="http://www.earnings.com/fin/earnListing.jsp?tckr=&exch=&eff=&dat +e=2003-05-04"; my $content=get $url; my $te = new HTML::TableExtract( headers => [qw(Company Symbol Estimate Actual)] ); $te->parse($content); # Examine all matching tables foreach my $ts ($te->table_states) { print "Table (", join(',', $ts->coords), "):\n"; foreach my $row ($ts->rows) { print join(',', @$row), "\n"; } }
Many thanks

Replies are listed 'Best First'.
Re: Able to Access Table Data But Not Sure How to Display Columns in Row Format
by Abstraction (Friar) on May 10, 2003 at 04:51 UTC
    Try

    #!/usr/bin/perl use warnings; use strict; use LWP::Simple; use HTML::TableExtract; my $url; $url="http://www.earnings.com/fin/earnListing.jsp?tckr=&exch=&eff=&dat +e=2003-05-04"; my $content=get $url; my $te = new HTML::TableExtract( headers => [qw(Company Symbol Estimate Actual)] ); $te->parse($content); # Examine all matching tables foreach my $ts ($te->table_states) { print "Table (", join(',', $ts->coords), "):\n"; foreach my $row ($ts->rows) print join ',', grep { s/\s{2,}//g; } @$row; print "\n"; } }
    Output:
    ACME Communications, Inc.,ACME,-$0.43, -$0.67 American Axle & Manufacturing Holdings Inc,AXL,$0.84, $1.02 Arch Chemicals Inc,ARJ,-$0.23, $0.11 Barry (R G) Corporation,RGB,n/a, Boots&Coots/Int Well,WEL,n/a, $999.00 Cameco Corporation,CCJ,n/a, Chevron Texaco Corporation,CVX,$1.29, Cigna Corp,CI,$1.27, $1.46 DTE Energy Company,DTE,$1.26, Gaylord Entertainment Co. (New),GET,n/a, Grant Prideco Inc,GRP,$0.02, $0.04 Grupo Financiero Galicia S.A. - American Depositary Shares Representin +g Class B*,GGAL,n/a, Hardinge, Inc.,HDNG,n/a, Hearst - Argyle Television Series A,HTV,$0.39, $0.11 Home Properties Of Ny Inc.,HME,$0.77, $0.60 Insmed, Inc.,INSM,-$0.33, JP Realty Inc.*,JPR,$0.64, Mge Energy Inc.,MGEE,n/a, OSI Systems, Inc.,OSIS,$0.23, $0.29 OXiGENE, Inc.,OXGN,-$0.23, Pinnacle West Capital Corp.,PNW,$0.57, Plains Resources, Inc,PLX,$0.41, Sun Communities Inc.,SUI,$0.88, $0.92 Superior Energy Service Inc,SPN,$0.07, $0.10 Tanox, Inc.,TNOX,-$0.19, -$0.14 Tyler Technologies Inc,TYL,$0.04,
Re: Able to Access Table Data But Not Sure How to Display Columns in Row Format
by CountZero (Bishop) on May 09, 2003 at 22:39 UTC

    Just guessing: perhaps do a chomp on your data?

    CountZero

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