First of all, do yourself a favour and install HTML::TokeParser::Simple. Your code then becomes

#!/usr/bin/perl -w use diagnostics; use strict; use HTML::TokeParser::Simple; my $filename = '/Users/peternelson/Desktop/atdstudy.html'; my $stream = HTML::TokeParser::Simple->new( $filename ) || die "Couldn't read HTML file $filename: $!"; while ( my $token = $stream->get_token ) { LOOK: { if ( $token->is_comment and $token->as_is eq '<!-- InstanceBeginEditable name="art +icle" -->' ) { goto PARSE; } else { next; } } PARSE: { if ( $token->is_comment and $token->as_is eq '<!-- InstanceEnd -->' ) { exit; } elsif ( $token->is_text ) { print $token->as_is; } next PARSE; } }

That loop doesn't work, because next doesn't work that way. You are using it inside a naked block, in which it skips execution of the rest of the block. Since the block only executes once, next LABEL is effectively the same as last LABEL. It doesn't at all affect execution flow in the surrounding loop, which seems to be what you hoped it'd do.

Your problem here is an ideal match for the flip-flop operator:

while ( my $token = $stream->get_token ) { if( ( $token->is_comment and $token->as_is eq '<!-- InstanceBeginEditable name="art +icle" -->' ) .. ( $token->is_comment and $token->as_is eq '<!-- InstanceEnd -->' ) ) { print $token->as_is if $token->is_text; } }

Makeshifts last the longest.


In reply to Re: Extracting HTML between comments by Aristotle
in thread Extracting HTML between comments by pnelson

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.