parsing in wrong order?

G

Geoff Cox

Hello,

I have just come back to the kind of code shown in the extract below -
problem is that although the code works, it does not output the data
in the same order as in the html files.

I would like to get successive sections of

<h2>
<p>
<options>

but am getitng all the <h2> and <p> and then all the <options> data.

Can anyone see the "obvious" from the code below?

The

if ( $tagname eq 'option' ) {

main::choice( $attr->{ value } );

}

ought, I would have thought, go off and get the <option> data and then
return to work through the html in the order found in the html file??

Cheers

Geoff



package MyParser;
use base qw(HTML::parser);
use strict;
use diagnostics;

my ($in_heading,$in_p, $fh);

sub register_fh {
$fh = $_[1];
}

sub reset { ($in_heading,$in_p)=(0,0)}

sub start {

my ( $self, $tagname, $attr, undef, $origtext ) = @_;

if ( $tagname eq 'h2' ) {
$in_heading = 1;
return;
}

if ( $tagname eq 'p' ) {
$in_p = 1;
return;
}

if ( $tagname eq 'option' ) {

main::choice( $attr->{ value } );

}

}

sub end {
my ( $self, $tagname, $origtext ) = @_;
if ( $tagname eq 'h2' ) {
$in_heading = 0;
return;
}

if ( $tagname eq 'p' ) {
$in_p = 0;
return;
}
}

sub text {
my ( $self, $origtext ) = @_;
print $fh "<h2>$origtext</h2> \n" if $in_heading;
print $fh "<p>$origtext</p> \n" if $in_p;

}

package main;

use File::Find;
 
G

Geoff Cox

On Tue, 12 Oct 2004 20:20:13 GMT, Geoff Cox

I seem to have found the error - of all things it seems to be an HTML
error !

Cheers

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top