Advertisement
Xliff

Yes, but where?!? -- Directive d not applicable for type Str

Apr 7th, 2016
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.10 KB | None | 0 0
  1. #/usr/bin/perl6
  2.  
  3. my ($index, $newIndex) = (5, 1);
  4. my ($indexF, $newIndexF);
  5.  
  6. sub readFile {
  7.     my $indexFH = open (my $fn = sprintf "index_split_%03d.html", $index++), :r
  8.         or die "Can't open file '$fn': $!";
  9.    
  10.     $indexF = $indexFH.slurp-rest;
  11.     $indexFH.close;
  12. }
  13.  
  14. sub writeFile {
  15.     my $newIndexFH = open (sprintf "newinidex_split_%03d.html", $newIndex++), :w;
  16.     $newIndexFH.print($newIndex);
  17.     $newIndexFH.close;
  18.  
  19.     say "Wrote new index file $newIndex.";
  20. }
  21.  
  22. readFile() && $newIndexF = $indexF if !$newIndexF.defined;
  23.  
  24. repeat {
  25.     readFile();
  26.     if ($index ~~ /'<h1>'/) {
  27.         writeFile();
  28.         $newIndexF = $index;
  29.         next;
  30.     }
  31.  
  32.     $newIndexF ~~ s| '</p>' \v '</body>' \v '</html>' $||;
  33.     $newIndexF ~~ s!('.' | '!' | '?')$$|$\0 !!;
  34.     $indexF ~~s |^^.+?\<p.+?\>||;
  35.     $index ~= $newIndexF;
  36. } until $newIndex > 418;
  37.  
  38. writeFile();
  39.  
  40.  
  41. ===
  42. Output
  43. ===
  44.  
  45. $ perl6 reSplit.pl
  46. Directive d not applicable for type Str
  47.   in any  at /home/cbwood/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm line 1
  48.   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