#!/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";
}
####
#!/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";
}
##
##
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
##
##
Array @html_files do
##
##
#!/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;
}