How to deal with Chinese in a Perl program on a mac
October 14, 2011 2:35 AM Subscribe
Working with Chinese and English text, in a Perl programme, on a Mac. I feel like an idiot.
I need to write a Perl programme on my mac to shuffle some Chinese sentences. None of Aquamacs, TextEdit, Pages or Word seems to provide support. Googling unicode support provides a tsunami of information that doesn't seem to help.
Listing the various combinations I have tried would be a monument only to human doggedness and stupidity. They all result in any combination of files in which the Chinese is corrupt, files which Perl thinks are binary and illegal, files which terminal thinks are binary, or similar.
To summarize the challenge, If I could do the following, I would be happy:
/usr/bin/perl -w
$string = "两个艺术家交换了签名。";
print $string, "\n";
Any suggestions?
posted by stonepharisee to computers & internet (5 answers total)
How can I output UTF-8 from Perl?
http://stackoverflow.com/questions/627661/how-can-i-output-utf-8-from-perl
I think you want:
#!/usr/bin/env perl -w
use strict;
use utf8;
my $str = '两个艺术家交换了签名。';
binmode(STDOUT, ":utf8");
print( "$str\n" );
Apparently this answer is also correct, i.e. using the following before the print statement:
use open qw/:std :utf8/;posted by asymptotic at 2:51 AM on October 14, 2011