Skip to content

Instantly share code, notes, and snippets.

@ggl
Last active September 10, 2016 07:47
Show Gist options
  • Save ggl/205c14e4271a6b916870 to your computer and use it in GitHub Desktop.
Save ggl/205c14e4271a6b916870 to your computer and use it in GitHub Desktop.
Replace Turkish UTF-8 glyphs with Romanian ones
#!/usr/bin/env perl
use strict;
use warnings;
if (@ARGV < 1) {
print "usage: $0 <file>\n";
exit 0;
};
my %arg = (
fin => $ARGV[0],
fout => $ARGV[1] ? $ARGV[1] : $ARGV[0].'.out'
);
my %fixes = (
"\x{015F}" => "\x{219}",
"\x{15E}" => "\x{218}",
"\x{162}" => "\x{21A}",
"\x{163}" => "\x{21B}",
"\x{E3}" => "\x{103}",
"\x{C3}" => "\x{102}"
);
open(my $in, "<:encoding(UTF-8)", $arg{fin}) or die "Cannot open file $arg{fin}: $!";
open(my $out, ">:encoding(UTF-8)", $arg{fout}) or die "Cannot open file $arg{fout}: $!";
while (my $line = <$in>) {
if (defined $line) {
foreach my $key (keys %fixes) {
$line =~ s/$key/$fixes{$key}/g;
};
print $out $line;
}
}
close($in);
close($out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment