0

I have something like this (it works):

perl -C -MText::Unidecode -n -i -e'print unidecode( $_)' unicode_text.txt 

and now i want to do the same in the script:

#!/usr/bin/perl -w -CSA use utf8; use Text::Unidecode; while(<>) { print unidecode($_); } 

but it doesn't work.

5
  • You should use strict;. Commented Jun 7, 2014 at 15:52
  • use utf8 serves no purpose here: you don't use utf-8 characters in the code. Commented Jun 7, 2014 at 15:57
  • What do you mean by "doesn't work"? It works for me. Commented Jun 7, 2014 at 15:59
  • In file i have "ąćęłńóśźżĄĆĘŁŃÓŚŹŻ" and i want to get "acelnoszzACELNOSZZ", but I got "AAAAAA3AAoA1/4AAAAAAAA1A>> " Commented Jun 7, 2014 at 16:04
  • 2
    Your one-liner produces no output for me using Perl 5.20 and Text::Unidecode v0.04. However, there is at least one issue I spot when I attempt to run your full sample code. This line: #!/usr/bin/perl -w -CSA produces an error message: Too late for "-CSA" option at...... I believe the -CSA can be replaced in the script with use open ':encoding(utf8)';. Commented Jun 7, 2014 at 16:13

1 Answer 1

2

You should have got the error message

Too late for "-CSA" option 

which is what makes the program read the input file as UTF-8-encoded.

Instead you need to put

use open qw( :std :utf8 ); 

before the while loop, which does the same as -CS on the command line, i.e. to set the STDIN, STDOUT and STDERR handles to UTF-8 encoding

Sign up to request clarification or add additional context in comments.

2 Comments

Does that result in you getting some output from his script? I would have posted this answer, but haven't been able to get Text::Unidecode to do anything useful... at least when used with Perl5.20.
@DavidO: I am on version 20 and it works fine. I presume you've put a file name in @ARGV?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.