Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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