in reply to Re: How to extract untouched content of html tag with HTML::Parser
in thread How to extract untouched content of html tag with HTML::Parser

How do you save the output to a varible so it can be used later?
  • Comment on Re^2: How to extract untouched content of html tag with HTML::Parser

Replies are listed 'Best First'.
Re^3: How to extract untouched content of html tag with HTML::Parser
by ig (Vicar) on Jul 26, 2013 at 17:15 UTC

    That depends what you mean by later. Perhaps something like the following would work for you?

    sub start_handler { my $self = shift; my $tagname = shift; my $attr = shift; my $text = shift; my $variable = ''; return unless ( $tagname eq 'div' and $attr->{id} eq 'body' ); $self->handler( start => sub { $variable .= shift }, "text" ); $self->handler( text => sub { $variable .= shift }, "text" ); $self->handler(end => sub { my ($endtagname, $self, $text) = @_; if($endtagname eq $tagname) { later($variable); $self->eof; } else { $variable .= $text; } }, "tagname,self,text"); } sub later { my ($variable) = @_; ## do something with $variable }