On Thursday, April 17, 2003, at 10:35 PM, SADAHIRO Tomoyuki wrote:
use Encode;
use Test::More 'no_plan';
use strict;
use warnings;
use utf8;
# This string is "What is unicode?" in arabic.
# Hence it's got plenty of right to left characters.
my $text = "ما هي الشفرة الموحدة يونِكود ؟";
# make sure that the utfness of the string is known by perl
ok (Encode::is_utf8 ($text), 'utf8 flag is on');
# perldoc unicode says:
# For example, "\p{BidiR}" matches characters that are normally
written right to left.
like ($text, qr/\p{BidiR}/, 'text has some right to left
characters');
I am impressed to find that Mail.app (v1.2.5) of MacOS X not only
supports rendering Arabic but also selects text from right to left. I
also found that Stickies and TextEdit support the text (these are not
surprising). The biggest surprise was that I could actually paste the
text to Terminal.app!
But I don't want any of them for perl scripts. Is there a good text
editor (MacOS X or not) that supports that?
BTW, If you want to exchange your perl script but your recepients are
stuck with ASCII, you can use 'piconv -f utf8 -t ascii -p'. Here is
what it said.
If you have a Unicode-savvy terminal emulator, it is worth trying the
script below;
#!/usr/local/bin/perl
use strict;
use warnings;
my $text = "\x{0645}\x{0627} \x{0647}\x{064a}
\x{0627}\x{0644}\x{0634}\x{0641}\x{0631}\x{0629}
\x{0627}\x{0644}\x{0645}\x{0648}\x{062d}\x{062f}\x{0629}
\x{064a}\x{0648}\x{0646}\x{0650}\x{0643}\x{0648}\x{062f} \x{061f}";
binmode(STDOUT => ':utf8');
$text =~ s/(\p{BidiAL}+)/print $1, "\n"/eg;
__END__
As you see since non-ASCII chars are in \x{} form, you need neither
'use Encode' nor even 'use utf8'.
Dan the Encode Mantainer