Created
March 19, 2020 21:33
-
-
Save kylebgorman/1b2e5a2d2d5abe12e50c7b5772985460 to your computer and use it in GitHub Desktop.
Converts from printable ASCII to a 27-character vocabulary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use open ":encoding(ascii)"; | |
binmode STDIN, ":encoding(ascii)"; | |
binmode STDOUT, ":encoding(ascii)"; | |
binmode STDERR, ":encoding(ascii)"; | |
while (<>) { | |
$_ = uc; # Case-folds. | |
s/'//g; # Removes /'/ (right quotes and apostrophe). | |
s/[\d\p{PosixPunct}]/ /g; # Replaces digits and punctuation with space. | |
s/\s+/ /g; # Maps whitespace spans to a single / /s. | |
s/^\s+|\s+$//g; # Removes edge whitespace. | |
print "$_\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment