-
Notifications
You must be signed in to change notification settings - Fork 44
/
unidecode.pl
executable file
·62 lines (49 loc) · 1.5 KB
/
unidecode.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl -T
#
# Author: Hari Sekhon
# Date: 2012-04-06 21:01:42 +0100 (Fri, 06 Apr 2012)
#
# https://github.com/HariSekhon/DevOps-Perl-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn
# and optionally send me feedback to help improve or steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
$DESCRIPTION="Converts UTF characters to ASCII
Works as a standard unix filter program, reading from file arguments or standard input and printing to standard output
Known Issues: uses the Text::Unidecode CPAN module, which seems to convert unknown chars to \"a\"
See also unidecode.py (pip install unidecode) which contains a CLI program to do this";
$VERSION = "0.6.3";
use strict;
use warnings;
use utf8;
#use Data::Dumper;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use Text::Unidecode; # For changing unicode to ascii
my $file;
%options = (
"f|files=s" => [ \$file, "File(s) to unidecode, non-option arguments are also counted as files. If no files are given uses standard input stream" ],
);
remove_timeout;
get_options();
my @files = parse_file_option($file, "args are files");
sub decode ($) {
my $string = shift;
chomp $string;
print unidecode("$string\n");
}
if(@files){
foreach my $file (@files){
my $fh = open_file $file;
while(<$fh>){ decode($_) }
}
} else {
while(<STDIN>){ decode($_) }
}