My question is with HTML::Parser but I also wonder if I am approaching this issue the correct way. I am trying to parse through a web-page and pull out the information I want which I would like to write into a text file or into memory. Here is a sample of some of the web page:
tr </tr><tr> <td><font size="2" face="Arial,Helvetica"> <hr size="2" width="100%"> Title: <b>2004-10-15 Off Season Rosters</b><BR> Post by <b>sydvicious</b> on <b>Oct 15<sup>th</sup>, 2004, 7:24pm< +/b> <hr width="100%" size="1"> I know, the keeper years all say &quot;1&quot;.<br><br><pre><br>TR +ANSACTIONS:<br><br>Scott - Activated Catalanotto_Frank/TOR; Waived Ca +stilla_Vinny/COL<br>Scott - Activated Day_Zach/MON; Waived Reese_Poke +y/BOS<br>Scott - Activated Hernandez_Runelvys/KCA; Waived Lowe_Derek/ +BOS<br>Scott - Activated VanBenschoten_John/PIT; Waived Quantrill_Pau +l/NYA<br>Scott - Activated Williamson_Scott/BOS; Waived Reyes_Dennys/ +KCA<br>Sean - Activated Burnett_Sean/P

Obviously, this is a parial HTML listing from the web page. I am trying to pull the names in the HTML so I can do some other things to them. Using the following perl, I am able to use HTML::parser and my vague understanding of it to print out what I would like. My questions are: 1) can I have the print statement in the subroutine "text" directed into a file or into an array for use outside of the package? 2) is there another way that I can approach this problem that I am completely missing other than HTML::Parser?
#!d:/perl56/bin use strict; { package HTMLParser; use base "HTML::Parser"; sub text { my ($self, $origtext) = @_; $origtext =~ s/&nbsp;//g; $self->{TEXT} .= $origtext; ### Read through hash and test each line against array @field = qw (C 1B 2B 3B SS OF1 OF2 OF3 DH B1 B2 B3 B4 B5 B6 B7 + B8 SP1 SP2 SP3 SP4 SP5 SW1 SW2 SW3 SW4 SW5 SW6 SW7 RP1 RP2 RP3 RP4 R +P5 RP6 RP7 IR); my @test = split(/\s*[ ]/,$origtext); foreach $line (@field) { if ($test[0] eq $line) { print "$test[1]\n"; } } } } my $leaguefile = $ARGV[0]; open(DATAFILE1,"$leaguefile") || die "Cannot open test file"; my $sp = new HTMLParser; while (<DATAFILE1>) { $sp->parse_file($_); } $sp->eof; close DATAFILE1;

In reply to html::parser question by treebeard

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.