gem ruby-perl ; Ruby
主題
Raw な Ruby からは Perl スクリプトを call するのは非常にメンドイらしい
gem を使って楽に call する
開発者には「バグレポートを出してくれれば対応するよ」という意味合いの文面は github にある。
目的
環境導入
gem install ruby-perl
コード作成
hello.rb
require 'perl' Perl.run %Q{print 'hello, Perl from Ruby\n'}
$ ruby hello.rb hello, Perl from Ruby
- foreach 処理
foreach.rb
require 'perl' Perl do run <<-EOF my @stone = ("Perl", "Ruby"); foreach my $gem (@stone){ print "$gem\n"; } EOF end
$ ruby foreach.rb Perl Ruby
異常
require 'perl' Perl.run %Q{ pInt 'hello, world\n' }
String found where operator expected at (eval 1) line 2, near "pInt 'hello, world'" (Might be a runaway multi-line '' string starting on line 1) (Do you need to predeclare pInt?)
[1]
Perl 文法ミスによる Perl.run の例外処理をしたが、error を出力していなかった
begin Perl.run %Q{ pInt 'hello, world\n' } #=> no exception rescue => e p e.class # 以下 2 行が実行されず p e.message # end
情報元 # thanks