[Erlang LT] Regexp Perl And Port

Keiichi Daiba
Keiichi DaibaNTT Resonant Inc.
[LT] Regexp, Perl, and Port

          id:kdaiba
whoami

 id:kdaiba
 Erlang newbie
 Perl Monger
     Yokohama.pm
     Shibuya.pm
     Tokyo.pm
     Now, setting up quot;Japan Perl Associationquot;
         http://trac.endeworks.jp/trac/tpfj/wiki
 Infrastructure Engineer
Erlang supports unicode in R12B-5
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 ...
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].
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]
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;
Can't I use utf-8 now ?

use Erlang::Port to see Unicode
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().
You'll get returns on STDERR

寿限無、寿限無、五劫の擦り切れ、海砂利水魚、水行末、雲来末、
風来末、食う寝る所に住む所、薮ら柑子のぶら柑子、パイポ、パイ
ポ、パイポのシューリンガン、シューリンガンのグーリンダイ、グーリン
ダイのポンポコピーのポンポコナーの長久命の長助
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).
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;
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();
}
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;
}
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 ) {
      quot;quot;;
  }
  elsif ( ref($obj) && UNIVERSAL::isa( $obj, 'Erlang::Atom' ) ) {
      $$obj;
  }
  elsif ( ref($obj) && UNIVERSAL::isa( $obj, 'Erlang::Binary' ) ) {
      $$obj;
  }
  else { undef; }
}
quot;song and dancequot; too long ?

      I'm sorry to be boring
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
Finally, you get ...

とんぼ
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 ....
1 of 19

Recommended

An Introduction to PHP... and Why It's Yucky! by
An Introduction to PHP... and Why It's Yucky!An Introduction to PHP... and Why It's Yucky!
An Introduction to PHP... and Why It's Yucky!Jorge Silva Jetter
302 views12 slides
Parse The Web Using Python+Beautiful Soup by
Parse The Web Using Python+Beautiful SoupParse The Web Using Python+Beautiful Soup
Parse The Web Using Python+Beautiful SoupJim Chang
3.6K views36 slides
Beware: Sharp Tools by
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Toolschrismdp
416 views60 slides
01 คำสั่งแสดงผล ในภาษาซี by
01 คำสั่งแสดงผล ในภาษาซี01 คำสั่งแสดงผล ในภาษาซี
01 คำสั่งแสดงผล ในภาษาซีPanatchakorn Chaiyanon
1.2K views7 slides
LAMP_TRAINING_SESSION_1 by
LAMP_TRAINING_SESSION_1LAMP_TRAINING_SESSION_1
LAMP_TRAINING_SESSION_1umapst
341 views21 slides
I, For One, Welcome Our New Perl6 Overlords by
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
715 views129 slides

More Related Content

What's hot

Cooking with Chef by
Cooking with ChefCooking with Chef
Cooking with ChefOrlando_Ruby_Users_Group
743 views61 slides
Joy of Six - Discover the Joy of Perl 6 by
Joy of Six - Discover the Joy of Perl 6Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6trexy
1.2K views45 slides
Perl6 grammars by
Perl6 grammarsPerl6 grammars
Perl6 grammarsAndrew Shitov
10.1K views89 slides
Iteration by
IterationIteration
IterationRich Price
300 views16 slides
Maybe you do not know that ... by
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...Viktor Turskyi
615 views39 slides
Nigel hamilton-megameet-2013 by
Nigel hamilton-megameet-2013Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013trexy
1.6K views31 slides

What's hot(20)

Joy of Six - Discover the Joy of Perl 6 by trexy
Joy of Six - Discover the Joy of Perl 6Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
trexy1.2K views
Maybe you do not know that ... by Viktor Turskyi
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...
Viktor Turskyi615 views
Nigel hamilton-megameet-2013 by trexy
Nigel hamilton-megameet-2013Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013
trexy1.6K views
Web Apps in Perl - HTTP 101 by hendrikvb
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
hendrikvb2.9K views
JSUG - Scala Lightning Talk by Michael Greifeneder by Christoph Pickl
JSUG - Scala Lightning Talk by Michael GreifenederJSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael Greifeneder
Christoph Pickl477 views
Bag of tricks by brian d foy
Bag of tricksBag of tricks
Bag of tricks
brian d foy4.4K views
第1回PHP拡張勉強会 by Ippei Ogiwara
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
Ippei Ogiwara2.2K views
Perl web frameworks by diego_k
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k670 views
Any event intro by qiang
Any event introAny event intro
Any event intro
qiang1.9K views
Using the Command Line with Magento by Matthew Haworth
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with Magento
Matthew Haworth1.3K views
Perl Sucks - and what to do about it by 2shortplanks
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
2shortplanks31.1K views
Webrtc mojo by bpmedley
Webrtc mojoWebrtc mojo
Webrtc mojo
bpmedley2K views
Anatomy of a PHP Request ( UTOSC 2010 ) by Joseph Scott
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Joseph Scott1.9K views

Viewers also liked

prova due by
prova dueprova due
prova dueamministratore
839 views12 slides
Drupal101 by
Drupal101Drupal101
Drupal101Rachel Vacek
1.6K views98 slides
Seize The Cloud by
Seize The CloudSeize The Cloud
Seize The CloudKeiichi Daiba
1.9K views58 slides
Content Marketing Optimization - TopRank Marketing by
Content Marketing Optimization - TopRank MarketingContent Marketing Optimization - TopRank Marketing
Content Marketing Optimization - TopRank MarketingTopRank Marketing Agency
2.8K views25 slides
Classics by
ClassicsClassics
ClassicsNinu
712 views23 slides
How to Win Friends and Influence the Influencers - TopRank Marketing by
How to Win Friends and Influence the Influencers - TopRank MarketingHow to Win Friends and Influence the Influencers - TopRank Marketing
How to Win Friends and Influence the Influencers - TopRank MarketingTopRank Marketing Agency
1.5K views24 slides

Viewers also liked(20)

Classics by Ninu
ClassicsClassics
Classics
Ninu712 views
How to Win Friends and Influence the Influencers - TopRank Marketing by TopRank Marketing Agency
How to Win Friends and Influence the Influencers - TopRank MarketingHow to Win Friends and Influence the Influencers - TopRank Marketing
How to Win Friends and Influence the Influencers - TopRank Marketing
Erlang with Regexp Perl And Port by Keiichi Daiba
Erlang with Regexp Perl And PortErlang with Regexp Perl And Port
Erlang with Regexp Perl And Port
Keiichi Daiba1.2K views
Content Marketing Strategy - The Future is Bright for Web Content by TopRank Marketing Agency
Content Marketing Strategy - The Future is Bright for Web Content Content Marketing Strategy - The Future is Bright for Web Content
Content Marketing Strategy - The Future is Bright for Web Content
Content Marketing - How to Optimize & Socialize for Better Performance by TopRank Marketing Agency
Content Marketing  - How to Optimize & Socialize for Better PerformanceContent Marketing  - How to Optimize & Socialize for Better Performance
Content Marketing - How to Optimize & Socialize for Better Performance
Create Demand and Influence with Co-Created Content for B2B Marketing by TopRank Marketing Agency
Create Demand and Influence with Co-Created Content for B2B MarketingCreate Demand and Influence with Co-Created Content for B2B Marketing
Create Demand and Influence with Co-Created Content for B2B Marketing
The butterfly_The flower by Ninu
The butterfly_The flowerThe butterfly_The flower
The butterfly_The flower
Ninu486 views
Web-Scale Discovery: Post Implementation by Rachel Vacek
Web-Scale Discovery: Post ImplementationWeb-Scale Discovery: Post Implementation
Web-Scale Discovery: Post Implementation
Rachel Vacek2.1K views
Evolution of Public Relations Through Content Marketing - Congreso PRORP by TopRank Marketing Agency
Evolution of Public Relations Through Content Marketing - Congreso PRORP  Evolution of Public Relations Through Content Marketing - Congreso PRORP
Evolution of Public Relations Through Content Marketing - Congreso PRORP

Similar to [Erlang LT] Regexp Perl And Port

Good Evils In Perl by
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
13.8K views109 slides
PERL Unit 6 regular expression by
PERL Unit 6 regular expressionPERL Unit 6 regular expression
PERL Unit 6 regular expressionBinsent Ribera
260 views21 slides
Perl Presentation by
Perl PresentationPerl Presentation
Perl PresentationSopan Shewale
4.9K views62 slides
Modern Perl by
Modern PerlModern Perl
Modern PerlMarcos Rebelo
1.8K views44 slides
Barely Legal Xxx Perl Presentation by
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
4.3K views63 slides
WindowsユーザのためのはじめてのPerlプログラミング by
WindowsユーザのためのはじめてのPerlプログラミングWindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミングYosuke HASEGAWA
2.3K views26 slides

Similar to [Erlang LT] Regexp Perl And Port(20)

Good Evils In Perl by Kang-min Liu
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu13.8K views
PERL Unit 6 regular expression by Binsent Ribera
PERL Unit 6 regular expressionPERL Unit 6 regular expression
PERL Unit 6 regular expression
Binsent Ribera260 views
Barely Legal Xxx Perl Presentation by Attila Balazs
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
Attila Balazs4.3K views
WindowsユーザのためのはじめてのPerlプログラミング by Yosuke HASEGAWA
WindowsユーザのためのはじめてのPerlプログラミングWindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミング
Yosuke HASEGAWA2.3K views
IST 561 Session 3, Feb 9, 2009--XHMTL and CSS basics by D.A. Garofalo
IST 561 Session 3, Feb 9, 2009--XHMTL and CSS basicsIST 561 Session 3, Feb 9, 2009--XHMTL and CSS basics
IST 561 Session 3, Feb 9, 2009--XHMTL and CSS basics
D.A. Garofalo371 views
Impacta - Show Day de Rails by Fabio Akita
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
Fabio Akita1.7K views
Perl Xpath Lightning Talk by ddn123456
Perl Xpath Lightning TalkPerl Xpath Lightning Talk
Perl Xpath Lightning Talk
ddn123456713 views
Dealing with Legacy Perl Code - Peter Scott by O'Reilly Media
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
O'Reilly Media12.8K views
Beginning Perl by Dave Cross
Beginning PerlBeginning Perl
Beginning Perl
Dave Cross3.9K views
Exploiting Php With Php by Jeremy Coates
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
Jeremy Coates32.6K views
☣ ppencode ♨ by Audrey Tang
☣ ppencode ♨☣ ppencode ♨
☣ ppencode ♨
Audrey Tang1.3K views
Ae internals by mnikolenko
Ae internalsAe internals
Ae internals
mnikolenko782 views
CGI With Object Oriented Perl by Bunty Ray
CGI With Object Oriented PerlCGI With Object Oriented Perl
CGI With Object Oriented Perl
Bunty Ray32.3K views
Out with Regex, In with Tokens by scoates
Out with Regex, In with TokensOut with Regex, In with Tokens
Out with Regex, In with Tokens
scoates4.5K views
Os Fetterupdated by oscon2007
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
oscon2007245 views

Recently uploaded

CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TShapeBlue
112 views34 slides
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
50 views35 slides
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineShapeBlue
181 views19 slides
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
146 views15 slides
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...ShapeBlue
117 views25 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
103 views23 slides

Recently uploaded(20)

CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue112 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue181 views
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue146 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue117 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue103 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue120 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue84 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty62 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software385 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue210 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue140 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely78 views
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... by ShapeBlue
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
ShapeBlue88 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue154 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue94 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views

[Erlang LT] Regexp Perl And Port

  • 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 quot;Japan Perl Associationquot; http://trac.endeworks.jp/trac/tpfj/wiki Infrastructure Engineer
  • 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 寿限無、寿限無、五劫の擦り切れ、海砂利水魚、水行末、雲来末、 風来末、食う寝る所に住む所、薮ら柑子のぶら柑子、パイポ、パイ ポ、パイポのシューリンガン、シューリンガンのグーリンダイ、グーリン ダイのポンポコピーのポンポコナーの長久命の長助
  • 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, quot;nquot;; $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 ) { quot;quot;; } elsif ( ref($obj) && UNIVERSAL::isa( $obj, 'Erlang::Atom' ) ) { $$obj; } elsif ( ref($obj) && UNIVERSAL::isa( $obj, 'Erlang::Binary' ) ) { $$obj; } else { undef; } }
  • 16. quot;song and dancequot; too long ? I'm sorry to be boring
  • 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
  • 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 ....