Calling a perl script

hi

i would like to call a perl script with ruby.
so i write puts ´perl test.pl´

how can i do it that my ruby programm gives the scrpit 1 and the perl
script adds one and gives the result back to my ruby script.

hope anyone can help me with a simple example
regards
max

“max” max@solution-x.com schrieb im Newsbeitrag
news:newscache$gcdy6h$q77$1@news.sil.at…

i would like to call a perl script with ruby.
so i write puts ´perl test.pl´

these must backquotes like in:

puts perl test.pl

when you want to write a new perl script, then do it directly in ruby
instead. integrating a big perl script that you don’t want to rewrite
seems to me the only case where call integration like this is appropriate.
what features are there in perl that you miss in ruby?

how can i do it that my ruby programm gives the scrpit 1 and the perl
script adds one and gives the result back to my ruby script.

in perl script (from memory):

print $ARGV[0] + 1, “\n”;

regards

robert

yes i have some perl libaries and no chance to use them via ruby
directly. i postet this problem on monday and someone told me that.
so i have to communicate with the scrpits. i know that it is not versy
good but i don’t want to rewrite all from the perl libary whcih would
take very long cause i didn’t write it.

thanks a lot for your answer. will try it then. :wink:
regards
max

Robert Klemme wrote:

···

“max” max@solution-x.com schrieb im Newsbeitrag
news:newscache$gcdy6h$q77$1@news.sil.at…

i would like to call a perl script with ruby.
so i write puts ´perl test.pl´

these must backquotes like in:

puts perl test.pl

when you want to write a new perl script, then do it directly in ruby
instead. integrating a big perl script that you don’t want to rewrite
seems to me the only case where call integration like this is appropriate.
what features are there in perl that you miss in ruby?

how can i do it that my ruby programm gives the scrpit 1 and the perl
script adds one and gives the result back to my ruby script.

in perl script (from memory):

print $ARGV[0] + 1, “\n”;

regards

robert

works fine. very cool. thank you.
prints me 2.

how can ruby read the 2? it is somethinng with the stdin or?

when i do
puts perl test.pl 1

it outputs 2
nil

regards
max

Robert Klemme wrote:

···

“max” max@solution-x.com schrieb im Newsbeitrag
news:newscache$gcdy6h$q77$1@news.sil.at…

i would like to call a perl script with ruby.
so i write puts ´perl test.pl´

these must backquotes like in:

puts perl test.pl

when you want to write a new perl script, then do it directly in ruby
instead. integrating a big perl script that you don’t want to rewrite
seems to me the only case where call integration like this is appropriate.
what features are there in perl that you miss in ruby?

how can i do it that my ruby programm gives the scrpit 1 and the perl
script adds one and gives the result back to my ruby script.

in perl script (from memory):

print $ARGV[0] + 1, “\n”;

regards

robert

how can ruby read the 2? it is somethinng with the stdin or?

when i do
puts perl test.pl 1

it outputs 2
nil

Use ‘irb’ until you find the answer: e.g.

Gavin Sinclair@NOSEDOG /tmp/a
$ cat > print2.sh
#!/bin/bash

echo 2

Gavin Sinclair@NOSEDOG /tmp/a
$ irb --simple-prompt

output = print2.sh
=> “2\n”
output.to_i
=> 2

···

From: “max” max@solution-x.com

Hello max,

Wednesday, December 11, 2002, 6:18:43 PM, you wrote:

yes i have some perl libaries and no chance to use them via ruby
directly. i postet this problem on monday and someone told me that.
so i have to communicate with the scrpits. i know that it is not versy

if this libraries is not OO, you can use them. i wrote module which
permits use of perl functions inside ruby like this:

include “PerlInside”
print “a”.length, length(“a”)

second length is actually evaluated by perl.exe :slight_smile: there is also
another library for calling perl functions from ruby, you can search
this on YARAA

···


Best regards,
Bulat mailto:bulatz@integ.ru

“max” max@solution-x.com schrieb im Newsbeitrag
news:newscache$bany6h$7v9$1@news.sil.at…

works fine. very cool. thank you.
prints me 2.

how can ruby read the 2? it is somethinng with the stdin or?

when i do
puts perl test.pl 1

it outputs 2
nil

oops, i forgot this point. sorry!

result = perl test.pl 1

regards

robert

regards
max

Robert Klemme wrote:

“max” max@solution-x.com schrieb im Newsbeitrag
news:newscache$gcdy6h$q77$1@news.sil.at…

i would like to call a perl script with ruby.
so i write puts ´perl test.pl´

these must backquotes like in:

puts perl test.pl

when you want to write a new perl script, then do it directly in ruby
instead. integrating a big perl script that you don’t want to rewrite
seems to me the only case where call integration like this is
appropriate.

···

what features are there in perl that you miss in ruby?

how can i do it that my ruby programm gives the scrpit 1 and the perl
script adds one and gives the result back to my ruby script.

in perl script (from memory):

print $ARGV[0] + 1, “\n”;

regards

robert

In article newscache$1ymy6h$gu9$1@news.sil.at,

yes i have some perl libaries and no chance to use them via ruby
directly. i postet this problem on monday and someone told me that.
so i have to communicate with the scrpits. i know that it is not versy
good but i don’t want to rewrite all from the perl libary whcih would
take very long cause i didn’t write it.

What I did in a situation like this was to write a wrapper around my Perl
library (in perl) that would take some arguments and return something,
like so:

#in ruby:

somePerlReturnedValue = perl MyLibWrapper #{someRubyValue}

#Perl wrapper (I’m forgetting Perl so please forgive any errors here)
use MyLib
$returnVal = myLibFunc($ARGV[0])
print $returnVal

Now I suppose that if you need to return several things from Perl that you
could parse a string that gets returned from the Perl side since I believe
that the backticks return a String object.

Now here’s a crazy idea: What we had some sort of Inline::Perl that used
YAML serialization to communicate between the two sides? There are YAML
serialization modules for both Ruby and Perl and they could be used to
pass objects back and forth between the two languages. An Inline::Perl
module would just sort of make the underlying communication between the
two transparent. Certainly most of the builtin types like Arrays, Hashes,
String and FixNums would be transportable, I’m not sure how user defined
classes would transfer, however (YAML dudes: is this feasable?)

Phil

···

max max@solution-x.com wrote:

“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America

hi

this sounds interestimg. well i downloaded the client libaries for
OpenSRS which i should use to write a new client. So i don’t know this
libaries very good. The whole documentation shows examples in perl.

But for any reason we want to have it in ruby. The libary should be used
cause so we stay up to date without doin to much.
So what is 00? Perl is also quite new for me.

What is YARAA? Do you have a link?

thanks a lot for your time
max

This message has been automatically forwarded from the ruby-talk mailing list by a gateway at pragprog.com. If it is SPAM, it did not originate at pragprog.com. Please report the original sender, and not us. Thanks! wrote:

···

Hello max,

Wednesday, December 11, 2002, 6:18:43 PM, you wrote:

yes i have some perl libaries and no chance to use them via ruby
directly. i postet this problem on monday and someone told me that.
so i have to communicate with the scrpits. i know that it is not versy

if this libraries is not OO, you can use them. i wrote module which
permits use of perl functions inside ruby like this:

include “PerlInside”
print “a”.length, length(“a”)

second length is actually evaluated by perl.exe :slight_smile: there is also
another library for calling perl functions from ruby, you can search
this on YARAA

This message has been automatically forwarded from the ruby-talk mailing list by a gateway at pragprog.com. If it is SPAM, it did not originate at pragprog.com. Please report the original sender, and not us. Thanks! wrote:

From: “max” max@solution-x.com

how can ruby read the 2? it is somethinng with the stdin or?

when i do
puts perl test.pl 1

it outputs 2
nil

Use ‘irb’ until you find the answer: e.g.

Gavin Sinclair@NOSEDOG /tmp/a
$ cat > print2.sh
#!/bin/bash

echo 2

Gavin Sinclair@NOSEDOG /tmp/a
$ irb --simple-prompt

output = print2.sh
=> “2\n”
output.to_i
=> 2

i wrote my test.pl with a print 2.
but when i execute output = test.pl

i get an error.

irb(main):001:0> output = test.pl
(irb):1: command not found: test.pl
“”

greetings
max

This message has been automatically forwarded from the ruby-talk mailing list by a gateway at pragprog.com. If it is SPAM, it did not originate at pragprog.com. Please report the original sender, and not us. Thanks! wrote:

Hello max,

Wednesday, December 11, 2002, 6:18:43 PM, you wrote:

yes i have some perl libaries and no chance to use them via ruby
directly. i postet this problem on monday and someone told me that.
so i have to communicate with the scrpits. i know that it is not versy

if this libraries is not OO, you can use them. i wrote module which
permits use of perl functions inside ruby like this:

include “PerlInside”
print “a”.length, length(“a”)

second length is actually evaluated by perl.exe :slight_smile: there is also
another library for calling perl functions from ruby, you can search
this on YARAA

correct my last posting. it works now that i can communicate.

my lib is OO. thought u wrote 00. my mistage. ups. :wink:

thanks a lot all that helped me
greetings
max

In article 83194626818.20021211183114@integ.ru,

···

Bulat Ziganshin bulatz@integ.ru wrote:

Hello max,

Wednesday, December 11, 2002, 6:18:43 PM, you wrote:

yes i have some perl libaries and no chance to use them via ruby
directly. i postet this problem on monday and someone told me that.
so i have to communicate with the scrpits. i know that it is not versy

if this libraries is not OO, you can use them. i wrote module which
permits use of perl functions inside ruby like this:

include “PerlInside”
print “a”.length, length(“a”)

second length is actually evaluated by perl.exe :slight_smile: there is also
another library for calling perl functions from ruby, you can search
this on YARAA

Is your PerlInside on the RAA? I didn’t find it there.

Phil

“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America

Now here’s a crazy idea: What we had some sort of Inline::Perl that used
YAML serialization to communicate between the two sides? There are YAML
serialization modules for both Ruby and Perl and they could be used to
pass objects back and forth between the two languages. An Inline::Perl
module would just sort of make the underlying communication between the
two transparent. Certainly most of the builtin types like
Arrays, Hashes,
String and FixNums would be transportable, I’m not sure how user defined
classes would transfer, however (YAML dudes: is this feasable?)

Similarly, couldn’t one wrap XML-RPC around the perl code?

James

···

Phil

Oh, yes. It’s the essence of YAML’s existence. User-defined classes are
merely native types that are explicitly typed in YAML. So this is a Ruby
Hash in YAML:

name: Peter Gorley
id: 345
email: peter.gorley@yaml.org

Perl would also load the above as a hash. But if you suddenly wanted to use
Ruby classes, the Hash would become typed:

— !!employee
name: Peter Gorley
id: 345
email: peter.gorley@yaml.org

You would then write handler code to load this YAML document as a class in
YAML.rb:

YAML::add_private_type( ‘employee’ ) { |type, val|
YAML::object_maker( EmployeeClass, val )
}

This is just one technique, though. There are several. I’d check out the
Cookbook [http://yaml4r.sf.net/cookbook/] and the YAML.rb docs
[http://yaml4r.sf.net/doc/] for more ideas.

_why

···

On Wednesday 11 December 2002 01:01 pm, Phil Tomson wrote:

Now here’s a crazy idea: What we had some sort of Inline::Perl that used
YAML serialization to communicate between the two sides? There are YAML
serialization modules for both Ruby and Perl and they could be used to
pass objects back and forth between the two languages. An Inline::Perl
module would just sort of make the underlying communication between the
two transparent. Certainly most of the builtin types like Arrays, Hashes,
String and FixNums would be transportable, I’m not sure how user defined
classes would transfer, however (YAML dudes: is this feasable?)

Hello Phil,

Wednesday, December 11, 2002, 11:01:03 PM, you wrote:

What I did in a situation like this was to write a wrapper around my Perl
library (in perl) that would take some arguments and return something,

i did this in general way. my library handles hashes/arrays of any
depth but don’t handle any class values

Now here’s a crazy idea: What we had some sort of Inline::Perl
that used YAML serialization to communicate between the two sides?
There are YAML serialization modules for both Ruby and Perl and
they could be used to pass objects back and forth between the two
languages.

good idea. i don’t know about yaml so i used pretty-print modules for
both languages

ps: it’s not on yaraa nor on this computer. i must carry this lib from
my home

– Best regards, Bulat mailto:bulatz@integ.ru

either

a) ./ is not in your path - try ./test.pl

b) the #! line of test.pl referes to the wrong path to perl

  #!/usr/local/bin/perl ??
  #!/usr/bin/perl       ??
  #!/bin/perl           ??
  etc.

  this can, in somecases, be sidestepped by using

  #!/usr/bin/env perl

  or

  #!/usr/local/bin/env perl

  instead, depending on the path to env.

-a

···

On Wed, 11 Dec 2002, max wrote:

i wrote my test.pl with a print 2.
but when i execute output = test.pl

i get an error.

irb(main):001:0> output = test.pl
(irb):1: command not found: test.pl
“”

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
SIGSIG – signature too long (core dumped)

In article NGEDJNFKAGDNDOIPFPBDGEHHDBAA.james@jamesbritt.com,

···

JamesBritt james@jamesbritt.com wrote:

Now here’s a crazy idea: What we had some sort of Inline::Perl that used
YAML serialization to communicate between the two sides? There are YAML
serialization modules for both Ruby and Perl and they could be used to
pass objects back and forth between the two languages. An Inline::Perl
module would just sort of make the underlying communication between the
two transparent. Certainly most of the builtin types like
Arrays, Hashes,
String and FixNums would be transportable, I’m not sure how user defined
classes would transfer, however (YAML dudes: is this feasable?)

Similarly, couldn’t one wrap XML-RPC around the perl code?

Sure, some form of XML serialization could be used too. I’m just partial
to YAML these days :wink:

Phil

“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America