On 4/6/07, yitzle <[EMAIL PROTECTED]> wrote:

I got an HTML file I want to parse.

Then there's a module on CPAN to help you. HTML is very complex stuff.

I have it stored in an array or whatever.
If I want to skip to a line and go from there, what's the best way?

I'm not sure what "skip to a line and go from there" means. Do you
want to locate a certain line by number? That's a good task for an
array index.

I'm thinking of doing something like:

    do {
        shift @input;
    } while ($input[0] =~ m/string-line to find/);

Real Perl programmers don't use indices. At least, not like that. But
let's say you want to process the lines after a pattern matches, but
not the matching line or the ones before. One straightforward way is
to set a flag:

 my $found;  # starts out false
 foreach (@input) {
   if ($found) {
     # $_ holds one of the lines you want to process
     &deal_with($_);
   } else {
     # Test $_ for the pattern
     $found = m/pattern/;
   }
 }
 warn "Hey, pattern never matched" unless $found;

Note that the line with the pattern match assigns the result (a
Boolean value) to $found. (It's not doing a pattern match _against_
$found.) But, again, are you searching a text file or an HTML
document? It's probably an oversimplification to use ordinary
text-handling tools to handle the complexity of HTML; consider a
module.

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to