Leser: 1
7 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl -w
#use strict;
#use warnings;
use HTML::Parser;
my @links;
my $string = qq~<title>Hallo das ist ein Titel</title><a href="/test1.htm">linktext1</a> Ein anderer Text
<a href="url2">linktext2</a> text~;
my $p = HTML::Parser->new();
$p->handler(start => \&start_handler,"tagname,attr,self");
$p->parse($string);
sub start_handler{
return if(shift eq 'ccc');
#print my $tagname = shift;
my ($class) = shift->{class};
my $self = shift;
if($class eq 'title') { $self->handler(text => \&get_title, "dtext"); }
elsif($class eq 'a') { $self->handler(text => \&get_a, "dtext"); }
else { $self->handler(end => sub{ },"dtext"); }
#$self->handler(end => sub{push(@tests,[$class,$text]) if($tagname eq 'title')},"tagname");
}
sub get_title()
{
my ($test ) = @_;
print $test;
}
sub get_a()
{
#$self->handler(end => sub{push(@links,[$class,$text]) if($tagname eq 'a')},"tagname");
#foreach my $link(@links){
# print "Linktext: ",$link->[1],"\tURL: ",$link->[0],"\n";
#}
}
QuoteWelche Zeile ist denn "..."?\n\nUse of uninitialized value in line ....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sub start_handler{
my $class = shift;
#my ($class) = shift->{class};
my $attr = shift;
my $self = shift;
if($class eq 'title') {
$self->handler(text => \&get_title, "text");
#$self->handler(end => sub{ },"dtext");
}
elsif($class eq 'a') {
$self->handler(text => \&get_a, "dtext");
}
else { }
#$self->handler(end => sub{push(@tests,[$class,$text]) if($tagname eq 'title')},"tagname");
}
sub get_title()
{
print $title = shift;
}
7 Einträge, 1 Seite |