F
franck
Greetings
I have the following class:
#!/usr/bin/perl
package monParser;
use HTML:arser;
@ISA = qw(HTML:arser);
my $ligne;
my $flag = 0;
my %want = (tag => 'font',
attrs => { face => "Arial", size => "2" });
sub start_handler {
my($tag, $attr) = @_;
return unless $tag eq $want{tag};
foreach my $name ( keys %{$want{attrs}} ) {
return unless $attr->{$name} eq $want{attrs}{$name};
}; $flag = 1;
}
sub new
{
my ($class) = @_;
my $this = $class -> SUPER::new(api_version => 3,
start_h => [\&start_handler, "tagname, attr"],
end_h => [sub {$flag=0 if shift eq $want{tag}},
"tagname"],
text_h => [sub {$ligne.= shift, "\n" if $flag}, "dtext"],
);
$this -> {'LIGNE'} = $ligne;
bless ($this,$class);
return $this;
}
sub affiche
{
my ($this) = @_;
print $this->{'LIGNE'};
}
1;
I use this class in this script:
#!/usr/bin/perl -I /home/Perl/Programmes//module
use monParser;
my $p = monParser->new();
$p->parse_file("\/home\/Perl\/Programmes\/arrivee\/tempo\.txt") || die $!;
$p->affiche;
I would like to print the LIGNE attibut with the "affiche" method
It does not work !
What is the problem ?
Thanks.
Franck
I have the following class:
#!/usr/bin/perl
package monParser;
use HTML:arser;
@ISA = qw(HTML:arser);
my $ligne;
my $flag = 0;
my %want = (tag => 'font',
attrs => { face => "Arial", size => "2" });
sub start_handler {
my($tag, $attr) = @_;
return unless $tag eq $want{tag};
foreach my $name ( keys %{$want{attrs}} ) {
return unless $attr->{$name} eq $want{attrs}{$name};
}; $flag = 1;
}
sub new
{
my ($class) = @_;
my $this = $class -> SUPER::new(api_version => 3,
start_h => [\&start_handler, "tagname, attr"],
end_h => [sub {$flag=0 if shift eq $want{tag}},
"tagname"],
text_h => [sub {$ligne.= shift, "\n" if $flag}, "dtext"],
);
$this -> {'LIGNE'} = $ligne;
bless ($this,$class);
return $this;
}
sub affiche
{
my ($this) = @_;
print $this->{'LIGNE'};
}
1;
I use this class in this script:
#!/usr/bin/perl -I /home/Perl/Programmes//module
use monParser;
my $p = monParser->new();
$p->parse_file("\/home\/Perl\/Programmes\/arrivee\/tempo\.txt") || die $!;
$p->affiche;
I would like to print the LIGNE attibut with the "affiche" method
It does not work !
What is the problem ?
Thanks.
Franck