Thread Ersatz für URI::Find (114 answers)
Opened by bianca at 2014-05-05 11:32

bianca
 2014-05-05 20:53
#175273 #175273
User since
2009-09-13
6977 Artikel
BenutzerIn

user image
Das hab ich mal exakt so eingebaut in eine Kopie namens Find_eigenpatch.pm

Dann folgendes Testscript:
Code (perl): (dl )
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl -W
use strict;
use warnings;
use diagnostics;
use Data::Dumper;

my $testtext = <<TEXTPLAIN;
Dies ist ein kleiner
Test zur Erkennung von Hyperlinks test.de oder www.test.de oder http://www.test.de
oder https://www.testhttps.de
test Platzhalter ||2||||||||||||
oder (http://test.de/slash/pfad)
oder info\@test.example
Und hier ein Gemeinschaftstest: http://www.test.de/login_index.php?email=info\@test.example
mal schauen...
http://www.orthopäden-hennef.de
und noch das Dach ^
TEXTPLAIN

my $txt=$testtext;
identifylinks(\$txt,'<a href="%s" target="_blank">%s</a>','<a href="mailto:%s">%s</a>');
print "<pre>$txt</pre>";

#--------#
sub identifylinks {
    #
    # Erkennt und markiert Hyperlinks in einem Text
    #
    # Aufruf:
    # =======
    # my $testtext = 'test: http://www.test.de';
    # identifylinks (\$testtext,'<a href="%s" target="_blank">%s</a>','<a href="mailto:%s">%s</a>');
    # print $testtext;
    #
    my $text = $_[0];
    my $link = $_[1];
    my $email_link = (defined $_[2] ? $_[2] : '');
    if (eval "use URI::Find_eigenpatch; 1;") {
        my $finder = URI::Find->new(
            sub { return sprintf($link,@_); }
        );

        my $call = sub { return $_[0]; };
        if ($email_link ne '' && eval "use Email::Find; 1;" ) {
            my $finder = Email::Find->new(
                sub { return sprintf($email_link,$_[0]->format,$_[1]); }
            );
            $call = sub {
                my $text = shift;
                $finder->find(\$text);
                return $text;
            };
        }
        $finder->find($text,$call);
    }
}

Aber irgendwie kommt das noch nicht richtig raus. Ich kann hier nicht die ganze Ausgabe zeigen, weil battie dann eine "unknown exception" bringt. Aber das wichtigste hat sich nicht geändert:
Quote
<a href="http://www.orthop/" target="_blank">http://www.orthop/</a>õden-hennef.de

Was hab ich falsch gemacht?
10 print "Hallo"
20 goto 10

View full thread Ersatz für URI::Find