Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > parsing in wrong order?

Reply
Thread Tools

parsing in wrong order?

 
 
Geoff Cox
Guest
Posts: n/a
 
      10-12-2004
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;
 
Reply With Quote
 
 
 
 
Geoff Cox
Guest
Posts: n/a
 
      10-13-2004
On Tue, 12 Oct 2004 20:20:13 GMT, Geoff Cox
<(E-Mail Removed)> wrote:

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

Cheers

Geoff

>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;


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 08:58 PM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments