#!perl -w
use strict;
use FileHandle;
use File::DosGlob;
sub glob_args {
map { File::DosGlob::glob $_ } @_;
}
sub write_file {
my ($fname, $lbound, $ubound, $allviews) = @_;
my $fh = new FileHandle $fname, "w";
defined $fh or die "Can't open $fname for writing: $!\n";
my $lineno = 0;
for (grep {$_->{views}>=$lbound and $_->{views}<=$ubound} @$allviews) {
++$lineno;
local $_ = $_->{line};
s/^\d+\./$lineno./;
print $fh $_;
}
close $fh;
}
@ARGV = glob_args @ARGV;
my @allviews;
while (<>) {
/<b>(\d+)<\/b> views/ or next;
push @allviews, { views=>$1, line=>$_ };
}
@allviews = sort { $a->{views} <=> $b->{views} } @allviews;
write_file "1to25.htm", 1, 24, \@allviews;
write_file "25to50.htm", 25, 49, \@allviews;
write_file "50to75.htm", 50, 74, \@allviews;
write_file "75to100.htm", 75, 99, \@allviews;
write_file "centurian.htm", 100, 199, \@allviews;
__END__