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:
arser);
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;
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:
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;