[Erlang LT] Regexp Perl And Port

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    [Erlang LT] Regexp Perl And Port - Presentation Transcript

    1. [LT] Regexp, Perl, and Port id:kdaiba
    2. whoami id:kdaiba Erlang newbie Perl Monger Yokohama.pm Shibuya.pm Tokyo.pm Now, setting up \"Japan Perl Association\" http://trac.endeworks.jp/trac/tpfj/wiki Infrastructure Engineer
    3. Erlang supports unicode in R12B-5
    4. Try to print utf-8 perl -e 'map{printf \"%d,\",$_}(unpack \"C*\",\"寿\");print \"\\n\";' 229,175,191, 1> UniString = [229,175,191]. \"寿\" 2> io:format(\"~p~n\",[UniString]). \"寿\" ok 3> It's looks OK on mac's terminal. But ...
    5. When you run this script... #!/usr/local/bin/escript main(_) -> Item0 = \"寿\", Item1 = \"寿限\", Item2 = \"寿限無\", Item3 = [[229,175,191],[233,153,144],[231,132,161]], io:format(\"~p~n\", [Item0]), io:format(\"~p~n\", [Item1]), io:format(\"~p~n\", [Item2]), [io:format(\"~p~n\", [X]) || X <- Item3].
    6. You'll get returns, like below \"寿\" [229,175,191,233,153,144] [229,175,191,233,153,144,231,132,161] \"寿\" [233,153,144] [231,132,161]
    7. Do google There is a page, \"Representing Unicode characters in Erlang\" http://www.erlang.org/eeps/eep-0010.html It's a \"Erlang Enhancement Proposals (EEPs)\", #10 This proposal's STATUS http://www.erlang.org/eeps/ Standards Track EEP Accepted proposal NOT \"Proposal is implemented in OTP release R12B-5\"
    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(\"./perlsay.pl\"), perlsay:say(\"寿限無、寿限無、五劫の擦り切れ、海砂利水魚、水 行末、雲来末、風来末、食う寝る所に住む所、薮ら柑子のぶら柑子、 パイポ、パイポ、パイポのシューリンガン、シューリンガンのグーリンダ イ、グーリンダイのポンポコピーのポンポコナーの長久命の長助\"), perlsay:stop().
    10. You'll get returns on STDERR 寿限無、寿限無、五劫の擦り切れ、海砂利水魚、水行末、雲来末、 風来末、食う寝る所に住む所、薮ら柑子のぶら柑子、パイポ、パイ ポ、パイポのシューリンガン、シューリンガンのグーリンダイ、グーリン ダイのポンポコピーのポンポコナーの長久命の長助
    11. Easy erlang code and -module(perlsay). -export([say/1]). -export([start/1, stop/0]). -import(perlport, [call/2, stop/1]). say(String) -> call([say, String], perlsay). start(Script) -> perlport:start(Script, perlsay). stop() -> perlport:stop(perlsay).
    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, \"\\n\"; $str; }
    15. Spagetti Perl Script (4/4) sub _to_s { my $obj = shift; if ( defined($obj) && !ref($obj) ) { $obj; } elsif ( $obj && ref($obj) eq 'ARRAY' && @$obj == 0 ) { \"\"; } elsif ( ref($obj) && UNIVERSAL::isa( $obj, 'Erlang::Atom' ) ) { $$obj; } elsif ( ref($obj) && UNIVERSAL::isa( $obj, 'Erlang::Binary' ) ) { $$obj; } else { undef; } }
    16. \"song and dance\" too long ? I'm sorry to be boring
    17. You can use this code like this #!/usr/local/bin/escript main(_) -> perlre:start(\"./perlre.pl\"), perlsay:start(\"./perlsay.pl\"), F = perlre:match(\"赤とんぼ\",\"(\\\\p{Hiragana}+)\"), [perlsay:say(X) || X <- F], perlre:stop(), perlsay:stop(). # perlre.pl is a sample code of Erlang::Port
    18. Finally, you get ... とんぼ
    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 ....

    + daibadaiba, 12 months ago

    custom

    498 views, 1 favs, 0 embeds more stats

    How to print unicode on erlang with perl and open p more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 498
      • 498 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags