Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/usr/bin/perl6
- my ($index, $newIndex) = (5, 1);
- my ($indexF, $newIndexF);
- sub readFile {
- my $indexFH = open (my $fn = sprintf "index_split_%03d.html", $index++), :r
- or die "Can't open file '$fn': $!";
- $indexF = $indexFH.slurp-rest;
- $indexFH.close;
- }
- sub writeFile {
- my $newIndexFH = open (sprintf "newinidex_split_%03d.html", $newIndex++), :w;
- $newIndexFH.print($newIndex);
- $newIndexFH.close;
- say "Wrote new index file $newIndex.";
- }
- readFile() && $newIndexF = $indexF if !$newIndexF.defined;
- repeat {
- readFile();
- if ($index ~~ /'<h1>'/) {
- writeFile();
- $newIndexF = $index;
- next;
- }
- $newIndexF ~~ s| '</p>' \v '</body>' \v '</html>' $||;
- $newIndexF ~~ s!('.' | '!' | '?')$$|$\0 !!;
- $indexF ~~s |^^.+?\<p.+?\>||;
- $index ~= $newIndexF;
- } until $newIndex > 418;
- writeFile();
- ===
- Output
- ===
- $ perl6 reSplit.pl
- Directive d not applicable for type Str
- in any at /home/cbwood/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm line 1
- in any panic at /home/cbwood/.rakudobrew/moar-nom/install/share/nqp/lib/NQPHLL.moarvm line 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement