SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
[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 ....

Mais conteúdo relacionado

Mais procurados

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Joseph Scott
 

Mais procurados (20)

Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Joy of Six - Discover the Joy of Perl 6
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
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Iteration
IterationIteration
Iteration
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...
 
Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
JSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael GreifenederJSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael Greifeneder
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
 
Elixir on Containers
Elixir on ContainersElixir on Containers
Elixir on Containers
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Any event intro
Any event introAny event intro
Any event intro
 
Using the Command Line with Magento
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with Magento
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
 
Embedding perl
Embedding perlEmbedding perl
Embedding perl
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
 

Destaque

Classics
ClassicsClassics
Classics
Ninu
 

Destaque (20)

prova due
prova dueprova due
prova due
 
Optimized Blogging That Inspires Action
Optimized Blogging That Inspires ActionOptimized Blogging That Inspires Action
Optimized Blogging That Inspires Action
 
#Optimize Content & Customers - Search Congress Barcelona
#Optimize Content & Customers - Search Congress Barcelona#Optimize Content & Customers - Search Congress Barcelona
#Optimize Content & Customers - Search Congress Barcelona
 
Convergence: Social Media SEO Content Marketing SES Chicago 2011
Convergence: Social Media SEO Content Marketing SES Chicago 2011Convergence: Social Media SEO Content Marketing SES Chicago 2011
Convergence: Social Media SEO Content Marketing SES Chicago 2011
 
Classics
ClassicsClassics
Classics
 
Content Marketing Optimization - TopRank Marketing
Content Marketing Optimization - TopRank MarketingContent Marketing Optimization - TopRank Marketing
Content Marketing Optimization - TopRank Marketing
 
Amazon Ec2
Amazon Ec2Amazon Ec2
Amazon Ec2
 
Atom Pub
Atom PubAtom Pub
Atom Pub
 
aaa
aaaaaa
aaa
 
Seize The Cloud
Seize The CloudSeize The Cloud
Seize The Cloud
 
prova tre
prova treprova tre
prova tre
 
Drupal101
Drupal101Drupal101
Drupal101
 
Optimize & Socialize for Better Business Blogging
Optimize & Socialize for Better Business BloggingOptimize & Socialize for Better Business Blogging
Optimize & Socialize for Better Business Blogging
 
Web-Scale Discovery: Post Implementation
Web-Scale Discovery: Post ImplementationWeb-Scale Discovery: Post Implementation
Web-Scale Discovery: Post Implementation
 
Create Demand and Influence with Co-Created Content for B2B Marketing
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
 
Content Marketing - How to Optimize & Socialize for Better Performance
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
 
prova
provaprova
prova
 
[Erlang LT] Regexp Perl And Port
[Erlang LT] Regexp Perl And Port[Erlang LT] Regexp Perl And Port
[Erlang LT] Regexp Perl And Port
 
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
Evolution of Public Relations Through Content Marketing - Congreso PRORP
 
How to Win Friends and Influence the Influencers - TopRank Marketing
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
 

Semelhante a Erlang with Regexp Perl And Port

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
PERL Unit 6 regular expression
PERL Unit 6 regular expressionPERL Unit 6 regular expression
PERL Unit 6 regular expression
Binsent Ribera
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
Attila Balazs
 
WindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミングWindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミング
Yosuke HASEGAWA
 
Perl Xpath Lightning Talk
Perl Xpath Lightning TalkPerl Xpath Lightning Talk
Perl Xpath Lightning Talk
ddn123456
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
Wen-Tien Chang
 
Os Fetterupdated
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
oscon2007
 

Semelhante a Erlang with Regexp Perl And Port (20)

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
PERL Unit 6 regular expression
PERL Unit 6 regular expressionPERL Unit 6 regular expression
PERL Unit 6 regular expression
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
WindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミングWindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミング
 
IST 561 Session 3, Feb 9, 2009--XHMTL and CSS basics
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
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
 
Perl Xpath Lightning Talk
Perl Xpath Lightning TalkPerl Xpath Lightning Talk
Perl Xpath Lightning Talk
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
 
☣ ppencode ♨
☣ ppencode ♨☣ ppencode ♨
☣ ppencode ♨
 
Ae internals
Ae internalsAe internals
Ae internals
 
CGI With Object Oriented Perl
CGI With Object Oriented PerlCGI With Object Oriented Perl
CGI With Object Oriented Perl
 
Out with Regex, In with Tokens
Out with Regex, In with TokensOut with Regex, In with Tokens
Out with Regex, In with Tokens
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
 
Os Fetterupdated
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
 
Nop2
Nop2Nop2
Nop2
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Erlang with 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 ....