4. Try to print utf-8
perl -e 'map{printf quot;%d,quot;,$_}(unpack quot;C*quot;,quot;寿quot;);print quot;nquot;;'
229,175,191,
1> UniString = [229,175,191].
quot;寿quot;
2> io:format(quot;~p~nquot;,[UniString]).
quot;寿quot;
ok
3>
It's looks OK on mac's terminal. But ...
5. When you run this script...
#!/usr/local/bin/escript
main(_) ->
Item0 = quot;寿quot;,
Item1 = quot;寿限quot;,
Item2 = quot;寿限無quot;,
Item3 = [[229,175,191],[233,153,144],[231,132,161]],
io:format(quot;~p~nquot;, [Item0]),
io:format(quot;~p~nquot;, [Item1]),
io:format(quot;~p~nquot;, [Item2]),
[io:format(quot;~p~nquot;, [X]) || X <- Item3].
6. You'll get returns, like below
quot;寿quot;
[229,175,191,233,153,144]
[229,175,191,233,153,144,231,132,161]
quot;寿quot;
[233,153,144]
[231,132,161]
7. Do google
There is a page,
quot;Representing Unicode characters in Erlangquot;
http://www.erlang.org/eeps/eep-0010.html
It's a quot;Erlang Enhancement Proposals (EEPs)quot;, #10
This proposal's STATUS
http://www.erlang.org/eeps/
Standards Track EEP
Accepted proposal
NOT quot;Proposal is implemented in OTP release R12B-5quot;
8. Can't I use utf-8 now ?
use Erlang::Port to see Unicode
9. I made a perl script to printout utf-8
#!/usr/local/bin/escript
main(_) ->
perlsay:start(quot;./perlsay.plquot;),
perlsay:say(quot;寿限無、寿限無、五劫の擦り切れ、海砂利水魚、水
行末、雲来末、風来末、食う寝る所に住む所、薮ら柑子のぶら柑子、
パイポ、パイポ、パイポのシューリンガン、シューリンガンのグーリンダ
イ、グーリンダイのポンポコピーのポンポコナーの長久命の長助quot;),
perlsay:stop().
10. You'll get returns on STDERR
寿限無、寿限無、五劫の擦り切れ、海砂利水魚、水行末、雲来末、
風来末、食う寝る所に住む所、薮ら柑子のぶら柑子、パイポ、パイ
ポ、パイポのシューリンガン、シューリンガンのグーリンダイ、グーリン
ダイのポンポコピーのポンポコナーの長久命の長助
12. Spaghetti perl script (1/4)
#!/usr/local/bin/perl
package Erlang::Port::Say;
use strict;
use warnings;
use Erlang::Port;
caller or __PACKAGE__->main(@ARGV);
1;
13. Spaghetti perl code (2/4)
sub main {
my $pkg = shift;
Erlang::Port->new(
sub {
my $obj = shift;
my $port = shift;
my $ret = eval { _my_proc( $obj, $port ) };
$ret = $port->_newTuple( [ $port->_newAtom('error') => $@, ] )
if ($@);
$ret;
}
)->loop();
}
14. Spagetti perl Script (3/4)
sub _my_proc {
my $obj = shift;
my $port = shift;
if ( !UNIVERSAL::isa( $obj, 'ARRAY' ) ) {
return $port->_newTuple( [ $port->_newAtom('badarg'), $obj ] );
}
my $key = _to_s( $obj->[0] );
if ( !defined($key) || $key ne 'say' ) {
return $port->_newTuple( [ $port->_newAtom('badarg'), $obj ] );
}
my $str = _to_s( $obj->[1] );
if ( !defined($str) ) {
return $port->_newTuple( [ $port->_newAtom('badarg'), $obj ] );
}
print STDERR $str, quot;nquot;;
$str;
}
17. You can use this code like this
#!/usr/local/bin/escript
main(_) ->
perlre:start(quot;./perlre.plquot;),
perlsay:start(quot;./perlsay.plquot;),
F = perlre:match(quot;赤とんぼquot;,quot;(p{Hiragana}+)quot;),
[perlsay:say(X) || X <- F],
perlre:stop(),
perlsay:stop().
# perlre.pl is a sample code of Erlang::Port
19. Twist ending
I need to check B12-R5
Today I have bad feelings. So I download B12-R5. It shows,
Eshell V5.6.5 (abort with ^G)
But, when I check my mac's erl, it shows
Eshell V5.6.4 (abort with ^G)
I made a mumbo jumbo ....