S
sinoslav
I'm pretty new to Perl's object system and am trying to figure out how
to add a data field to my subclass of HTML:arser so that the
subclass can collect information into that data field as it parses an
HTML document. For example, let's say I want to collect an array
@names of all the NAME attributes of my <A> tags, and add a method
that returns that array:
{
Package MyParser;
use base HTML:arser;
sub start {
my ($self, $tag, $attr, $attrseq, $origtext) = @_;
if($tag eq "a") {
push @names, $attr->{name};
}
}
sub get_names {
return \@names;
}
....
}
How can I declare the @names array as a field of MyParser?
Many thanks!
Roger
to add a data field to my subclass of HTML:arser so that the
subclass can collect information into that data field as it parses an
HTML document. For example, let's say I want to collect an array
@names of all the NAME attributes of my <A> tags, and add a method
that returns that array:
{
Package MyParser;
use base HTML:arser;
sub start {
my ($self, $tag, $attr, $attrseq, $origtext) = @_;
if($tag eq "a") {
push @names, $attr->{name};
}
}
sub get_names {
return \@names;
}
....
}
How can I declare the @names array as a field of MyParser?
Many thanks!
Roger