Advertisement
sakuya-inu-izayoi

Untitled

Sep 26th, 2015
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.88 KB | None | 0 0
  1. #!/bin/env perl
  2.  
  3. # Source characters
  4. my @S = qw(p t t͡ʃ k s ʃ);
  5. # Replacement characters
  6. my @Z = qw(b d d͡ʒ g z ʒ);
  7.  
  8. # Boundaries
  9. my $V = "a|ə|e|o|i|u|ø|y";
  10.  
  11. use warnings;
  12. use strict;
  13.  
  14. my $filename = pop;
  15.  
  16. my $inverted = 0;
  17.  
  18. while ( $_ = shift )
  19. {
  20.   if(/--invert/)
  21.   {
  22.     $inverted = 1;
  23.   }
  24. }
  25.  
  26. # Open the file
  27. open(my $fh, "<", $filename);
  28.  
  29. # Read line by line
  30. while(<$fh>)
  31. {
  32.   # apply early transformations here
  33.  
  34.   # Go through each "source" => "replacement"
  35.   for(my $i = 0; $i < @S; $i++) {
  36.     # retrieve the source
  37.     my $item = $inverted?$Z[$i]:$S[$i];
  38.     # and replacement
  39.     my $rplc = $inverted?$S[$i]:$Z[$i];
  40.  
  41.     # replace the source by replacement inside the boundaries
  42.     s/((?:$V)+)$item((?:$V)+)/$1$rplc$2/gi
  43.  
  44.   }
  45.  
  46.   # insert any other transformations here
  47.  
  48.  
  49.   # print the line after modifications
  50.   print;
  51. }
  52.  
  53. close($fh);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement