Thread perl im debug-modus fahren
(18 answers)
Opened by lin at 2010-10-01 20:18
Hallo GwenDragon, hallo pq und unbek. Gast.
Das mit den oben genannten Fragen zu den Pfaden muss ich unbed. noch klären! ich werde mich da nochmals reinhängen. Eure Fragen sind wirlich gut! Wie auch immmer... ich hab aber folgendes gemacht: Ich habe das gewelchselt - von 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 #!/usr/bin/perl use strict; use warnings; use diagnostics; use File::Find::Rule; my @files = File::Find::Rule->file() ->name('einzelergebnis*.html') ->in( '/home/usr/perl/htmlfiles' ); foreach my $file(@files) { print $file, "\n"; } [/perl] zu dem Folgenden: [code=perl] #!/usr/bin/perl use strict; use warnings; use diagnostics; use File::Find::Rule; my @files = File::Find::Rule->file() ->name('einzelergebnis*.html') ->in( '.' ); foreach my $file(@files) { print $file, "\n"; } [/perl] und habe den folgenden output bekommen: [quote] htmlfiles/einzelergebnis80b5.html htmlfiles/einzelergebnisa0ef.html htmlfiles/einzelergebnis1b42.html htmlfiles/einzelergebnis5960.html htmlfiles/einzelergebnise523.html htmlfiles/einzelergebnis2c7e.html htmlfiles/einzelergebnisdf57.html htmlfiles/einzelergebnis2b53-2.html htmlfiles/einzelergebnisb1c0-2.html htmlfiles/einzelergebnis8e8b.html htmlfiles/einzelergebnisdcc1.html htmlfiles/einzelergebnis1dae-2.html htmlfiles/einzelergebnisa70d.html htmlfiles/einzelergebnis3cec.html htmlfiles/einzelergebnis3f1f.html htmlfiles/einzelergebnis1d2b.html htmlfiles/einzelergebnis396c.html htmlfiles/einzelergebnis2592.html htmlfiles/einzelergebnisdee0.html htmlfiles/einzelergebnis987b-2.html htmlfiles/einzelergebnise20b.html htmlfiles/einzelergebnised05.html htmlfiles/einzelergebnisdec3.html und 22 tausend weiteren Zeilen... ;-) [/quote] jetzt da die Vorübungen einiges geklärt haben muss ich daran gehen das HTML-parser-script (siehe unten) anzupassen. Also die Pfade zu defniieren: in $file the file/directory incl. und einen Pfad zu defniieren in $html_dir BTW – Bianca hat heute Morgen die Frage aufgeworfen was Array @html_files macht!!? Ist mir im Grunde auch noch nicht ganz klar!? Hier der Code des Parsers: [code=perl] #!/usr/bin/perl use strict; use warnings; use HTML::TokeParser; my $file = 'school.html'; my $p = HTML::TokeParser->new($file) or die "Can't open: $!"; my %school; while (my $tag = $p->get_tag('div', '/html')) { # first move to the right div that contains the information last if $tag->[0] eq '/html'; next unless exists $tag->[1]{'id'} and $tag->[1]{'id'} eq 'inhalt_large'; $p->get_tag('h1'); $school{'location'} = $p->get_text('/h1'); while (my $tag = $p->get_tag('div')) { last if exists $tag->[1]{'id'} and $tag->[1]{'id'} eq 'fusszeile'; # get the school name from the heading next unless exists $tag->[1]{'class'} and $tag->[1]{'class'} eq 'fm_linkeSpalte'; $p->get_tag('h2'); $school{'name'} = $p->get_text('/h2'); # verify format for school type $tag = $p->get_tag('span'); unless (exists $tag->[1]{'class'} and $tag->[1]{'class'} eq 'schulart_text') { warn "unexpected format: parsing stopped"; last; } $school{'type'} = $p->get_text('/span'); # verify format for address $tag = $p->get_tag('p'); unless (exists $tag->[1]{'class'} and $tag->[1]{'class'} eq 'einzel_text') { warn "unexpected format: parsing stopped"; last; } $school{'address'} = clean_address($p->get_text('/p')); # find the description $tag = $p->get_tag('p'); $school{'description'} = $p->get_text('/p'); } } print qq/$school{'name'}n/; print qq/$school{'location'}n/; print qq/$school{'type'}n/; foreach (@{$school{'address'}}) { print "$_\n"; } print qq/nDescription: $school{'description'}n/; sub clean_address { my $text = shift; my @lines = split "\n", $text; foreach (@lines) { s/^s+//; s/s+$//; } return @lines; } Freu mich auf nen Tipp beim Anpassen des Parserscripts!! Tx lin BTW - es hat die Formatierung des Beitrags verrissen - ich muss nochmals gucken warum..!? Mache ich noch!? Last edited: 2010-10-02 21:14:37 +0200 (CEST) |