Ruby to Perl translation

J

Jeremy Mclain

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?
 
E

Eivind Eklund

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.
 
A

Adrian Howard

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 :)
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 :)

Cheers,

Adrian
 
J

John Wells

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 :)

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 ;)
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Sat, 24 Nov 2007 01:05:01 +0900
Von: "John Wells" <[email protected]>
An: (e-mail address removed)
Betreff: Re: Ruby to Perl translation

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 ;)

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
 
M

M. Edward (Ed) Borasky

Axel said:
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?
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Sat, 24 Nov 2007 17:55:53 +0900
Von: "M. Edward (Ed) Borasky" <[email protected]>
An: (e-mail address removed)
Betreff: Re: Ruby to Perl translation
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
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Sun, 25 Nov 2007 15:37:13 +0900
Von: Ryan Davis <[email protected]>
An: (e-mail address removed)
Betreff: Re: Ruby to Perl translation

Soooo... you're NOT being sarcastic?
Dear Ryan,

mmmh. If two people say so, they've got to be right. :)

Best regards,

Axel
 
A

Adrian Howard

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 ;)

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 :)

Cheers,

Adrian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top