Passing results from sub class of html::parser
- From: "Gerwin" <g.h.vandoorn@xxxxxxxxx>
- Date: 31 Jan 2007 06:06:35 -0800
I'm trying to sub class HTML::Parser and store the parsed result in a
variable so I can access it again from outside the sub class. In the
code below the "text" method would print $text AND if I would say
"$vars->{'text_output'} = "test text";" it would also show "test
text" when calling "print $parser->getTextOutput();" but it will not
print the $text when saying "$vars->{'text_output'} = $text;"
What am I doing wrong here?
package MyParser;
use base qw(HTML::Parser);
my %vars = (
text_output => undef
);
sub text {
my ($self, $text) = @_;
$vars->{'text_output'} = $text;
}
sub getTextOutput {
return $vars->{'text_output'};
}
package main;
use LWP::Simple;
my $parser = MyParser->new;
my $url = @ARGV[0];
my $html = get $url; die "Couldn't get $url" unless defined $html;
$parser->parse( $html );
$parser->eof;
print $parser->getTextOutput();
.
- Prev by Date: FAQ 3.24 Why don't Perl one-liners work on my DOS/Mac/VMS system?
- Next by Date: sort an array unique.
- Previous by thread: FAQ 3.24 Why don't Perl one-liners work on my DOS/Mac/VMS system?
- Next by thread: sort an array unique.
- Index(es):