Ruby to Perl translation

I love the flexibility of writing scripts in Ruby but my work doesn’t
allow me to install the Ruby interpreter on my system. Does anyone know
of any tools that will translate my Ruby scripts into Perl scripts? My
Ruby scripts aren’t “Perlish” so it is not a trivial task to do it
manually. I know the frameworks are different and I can deal with that.
I mostly only care about the syntactic translation. Any suggestions?

On Nov 23, 2007 5:47 AM, Jeremy M. [email protected] wrote:

I love the flexibility of writing scripts in Ruby but my work doesn’t
allow me to install the Ruby interpreter on my system. Does anyone know
of any tools that will translate my Ruby scripts into Perl scripts? My
Ruby scripts aren’t “Perlish” so it is not a trivial task to do it
manually. I know the frameworks are different and I can deal with that.
I mostly only care about the syntactic translation. Any suggestions?

Actually, such a translator would have to be a full compiler, I think.
I don’t know any compiler for this, but if there are any specific
constructs you are having problems with, I’d be willing to help you
find a nice translation.

The primary problems I immediately see for a compiler is the
difference in true/false handling between Ruby and Perl, the integer
overflow problem, issues with native types (scalars, hashes, arrays
and code) not being objects, and the string/integer/float collapse
that happen around this.

I first thought that adding methods to objects etc would be a problem,
but thinking about it for a second, I see that this is fairly simple
to implement (on adding a method, you construct a new package that
inherit from the one the object is presently in, use *THING syntax to
add your method, add a DESTROY to get rid of the temporary package
space when your object is GCed while also calling the old DESTROY if
any).

Of course, the syntax to do object magic in Perl is horrible, compared
to Ruby. I’ve just not found much that isn’t doable, if I dig into it
and disregard that faint feeling of revulsion.

Eivind.

On 23 Nov 2007, at 04:47, Jeremy M. wrote:

I love the flexibility of writing scripts in Ruby but my work doesn’t
allow me to install the Ruby interpreter on my system.

Why (he asks curiously)? Any way of addressing that problem directly?

Does anyone know
of any tools that will translate my Ruby scripts into Perl scripts?

Ask them to install the CPAN Inline::Ruby module and see if they
accidentally install Ruby as a dependency :slight_smile:

My
Ruby scripts aren’t “Perlish” so it is not a trivial task to do it
manually.

What kind of things are causing problems?

I know the frameworks are different and I can deal with that.
I mostly only care about the syntactic translation. Any suggestions?

There’s nothing like a Ruby->Perl compiler that I’m aware of. Which
bits of Ruby syntax are do you like most? It might be easier to pick
some useful modules (e.g. Moose for OO) and stick with Perl. It
doesn’t have to look completely evil :slight_smile:

Cheers,

Adrian

On 11/23/07, Adrian H. [email protected] wrote:

There’s nothing like a Ruby->Perl compiler that I’m aware of. Which
bits of Ruby syntax are do you like most? It might be easier to pick
some useful modules (e.g. Moose for OO) and stick with Perl. It
doesn’t have to look completely evil :slight_smile:

As long as we’re wishing, it’d be nice to have it the other way
around. Some many legacy perl scripts, so little time to care about
perl anymore :wink:

-------- Original-Nachricht --------

Datum: Sat, 24 Nov 2007 01:05:01 +0900
Von: “John W.” [email protected]
An: [email protected]
Betreff: Re: Ruby to Perl translation

On 11/23/07, Adrian H. [email protected] wrote:

There’s nothing like a Ruby->Perl compiler that I’m aware of. Which
bits of Ruby syntax are do you like most? It might be easier to pick
some useful modules (e.g. Moose for OO) and stick with Perl. It
doesn’t have to look completely evil :slight_smile:

As long as we’re wishing, it’d be nice to have it the other way
around. Some many legacy perl scripts, so little time to care about
perl anymore :wink:

Is it true that Perl is written completely in C as Ruby is ?
Then, if you had an arbitrary, but fixed Perl script you wanted
to use in Ruby, if you could (possibly automatically) determine
what of the underlying C is actually used in that script, you could make
that work as a C extension of Ruby, couldn’t you ?

Best regards,

Axel

Then, to make these two work together (in Ruby or in Perl

Axel E. wrote:

Is it true that Perl is written completely in C as Ruby is ?
Then, if you had an arbitrary, but fixed Perl script you wanted
to use in Ruby, if you could (possibly automatically) determine
what of the underlying C is actually used in that script, you could make that work as a C extension of Ruby, couldn’t you ?

You’re being sarcastic, right?

-------- Original-Nachricht --------

Datum: Sat, 24 Nov 2007 17:55:53 +0900
Von: “M. Edward (Ed) Borasky” [email protected]
An: [email protected]
Betreff: Re: Ruby to Perl translation

Axel E. wrote:

Is it true that Perl is written completely in C as Ruby is ?
Then, if you had an arbitrary, but fixed Perl script you wanted
to use in Ruby, if you could (possibly automatically) determine
what of the underlying C is actually used in that script, you could make
that work as a C extension of Ruby, couldn’t you ?

You’re being sarcastic, right?

Dear Ed,

mmmh, probably, you’re right.

I’m not sure whether any Perl script existed that
I’d personally like to use in Ruby with the following additional
features:

  • no Ruby solution for the underlying problem on RAA,
  • I’d not be able to write one in Ruby in less time than the C extension
    approach would cost me ( and it sometimes takes me a long time to get
    to
    working code…).

I didn’t write that to offend anyone though.
Every three months, I find it bothersome that there seems to be no
negative lookahead in Ruby regexps, and just recently, I discovered
that there is a library that has that – written for Lua, partly
in C, partly in Lua, so I was wondering how much work it would be
to replace the C functions whose names start in ‘lua_’ by the actual
C code Lua is written in itself.
So, it wouldn’t be necessary to rewrite the whole language, but only
a part of it, which could make the resulting script more lightweight.
(Lua promises to be a very lightweight, C extension and glue language –
I don’t think the same holds true for Perl ;-)).

To do that for one application alone is certainly shooting with cannons
on birds, but if a specific grammar software achieving that were
available, one could borrow nice solutions from other scripting
languages more
easily …

I admit that starting this for Perl is probably extremely involved
and most likely practically infeasible … I just hoped that
someone had some nice code ready to solve all my problems – as has
happened so many times before with Ruby :).

Best regards,

Axel

-------- Original-Nachricht --------

Datum: Sat, 24 Nov 2007 19:32:08 +0900
Von: “Axel E.” [email protected]
An: [email protected]
Betreff: Re: Ruby to Perl translation

to use in Ruby, if you could (possibly automatically) determine
what of the underlying C is actually used in that script, you could
make
that work as a C extension of Ruby, couldn’t you ?

You’re being sarcastic, right?

Dear Ed,

in Perl, there is this:

http://kobesearch.cpan.org/htdocs/perl/CC.html

Maybe it works well for not-to-involved code.

Best regards,

Axel

On Nov 24, 2007, at 09:04 , Axel E. wrote:

You’re being sarcastic, right?
Dear Ed,

in Perl, there is this:

http://kobesearch.cpan.org/htdocs/perl/CC.html

Maybe it works well for not-to-involved code.

Soooo… you’re NOT being sarcastic?

-------- Original-Nachricht --------

Datum: Sun, 25 Nov 2007 15:37:13 +0900
Von: Ryan D. [email protected]
An: [email protected]
Betreff: Re: Ruby to Perl translation

Maybe it works well for not-to-involved code.

Soooo… you’re NOT being sarcastic?

Dear Ryan,

mmmh. If two people say so, they’ve got to be right. :slight_smile:

Best regards,

Axel

On 23 Nov 2007, at 16:05, John W. wrote:

On 11/23/07, Adrian H. [email protected] wrote:

There’s nothing like a Ruby->Perl compiler that I’m aware of. Which
bits of Ruby syntax are do you like most? It might be easier to pick
some useful modules (e.g. Moose for OO) and stick with Perl. It
doesn’t have to look completely evil :slight_smile:

As long as we’re wishing, it’d be nice to have it the other way
around. Some many legacy perl scripts, so little time to care about
perl anymore :wink:

The thing is that these sorts of automated conversion tools nearly
always give you code that’s a complete bugger to maintain. Wrap the
other code in some kind of RPC framework and leave it alone would be
my advice :slight_smile:

Cheers,

Adrian

On 24 Nov 2007, at 17:04, Axel E. wrote:
[snip]

in Perl, there is this:

http://kobesearch.cpan.org/htdocs/perl/CC.html

Maybe it works well for not-to-involved code.
[snip]

It’s never really worked as far as I am aware. I’ve a vague
recollection it’s going to be removed / actively deprecated in the
upcoming 5.10 release.

Adrian