From: Martin =?utf-8?B?U2Now7bDtm4=?= on
First off: I am new here and this is my first post after
lurking for quite some time.

Second off: I don't know much Python---yet.

Problem: I have come across a small open source application
that I find quite useful. It does have one major flaw though.
Its output is in imperial units. Converting isn't a big deal
for occasional use but if I start to use this stuff on a
regular basis...

So I down-loaded the source code and found this thing is written
in Perl.

Should I learn enough Perl to add the conversion? Probably
but this may be a nice excuse to get my Python education
going and if I do I might as well re-do the user interface.

If I do re-write this thing in Python I might need to learn both
Perl and Python...

Hence, are there any Perl to Python converters? So far I
have only found bridgekeeper which really is (was?) consultancy.
Apart from that I only find people recommending a manual re-write.

Any thoughts/recommendations?

TIA,

/Martin
From: zeph on
Python and Perl often have different design idioms - learning to write
*well* in a language involves understanding those idioms, and being
able to translate between languages involves understanding the source
language well enough to understand the intent of the program's code
(even if its poorly written), and understanding the target language
well enough to translate the intent into a design fitting the
language.

Perl and Python have enough syntactic similarities that you could, if
you wanted, just translate the program verbatim.

Overall, I would recommend adding your imperial->metric functionality
to the Perl code for now, and on your free time work on translating to
Python, so you don't feel rushed to get it finished. You will
probably come to understand the Perl code better after having worked
with it and been involved in a hands-on way with it. Likewise, you
will become even more familiar with it and with Python as you learn
how to translate the application.
From: Intchanter / Daniel Fackrell on
On Dec 9, 1:33 pm, martin.sch...(a)gmail.com (Martin Schöön) wrote:
> First off: I am new here and this is my first post after
> lurking for quite some time.
>
> Second off: I don't know much Python---yet.
>
> Problem: I have come across a small open source application
> that I find quite useful. It does have one major flaw though.
> Its output is in imperial units. Converting isn't a big deal
> for occasional use but if I start to use this stuff on a
> regular basis...
>
> So I down-loaded the source code and found this thing is written
> in Perl.
>
> Should I learn enough Perl to add the conversion? Probably
> but this may be a nice excuse to get my Python education
> going and if I do I might as well re-do the user interface.
>
> If I do re-write this thing in Python I might need to learn both
> Perl and Python...
>
> Hence, are there any Perl to Python converters? So far I
> have only found bridgekeeper which really is (was?) consultancy.
> Apart from that I only find people recommending a manual re-write.
>
> Any thoughts/recommendations?
>
> TIA,
>
> /Martin

Martin,

A full answer will depend a lot on several different factors,
including the length of the Perl code, what style it was written in
(there seem to be uncountably many possibilities), your experience
with languages in general, and with that style in particular.

In general, though, if your primary purpose is to learn Python and
ending up with a useful tool is secondary, I'd recommend rewriting the
tool from scratch, possibly keeping the Perl source handy. If the
existing tool is command-line based, you might also be able to write a
short script through which you can pipe the output of the original
program to handle the conversion.

Intchanter
Daniel Fackrell
From: Peter Chant on
Martin Sch��n wrote:

> Hence, are there any Perl to Python converters? So far I
> have only found bridgekeeper which really is (was?) consultancy.
> Apart from that I only find people recommending a manual re-write.
>
> Any thoughts/recommendations?

Voice of almost no experience. I once ran a fortran programme through a
fortran to c converter and when I saw the result I ran away screaming - it
did not look very human friendly.




--
http://www.petezilla.co.uk

From: J Kenneth King on
martin.schoon(a)gmail.com (Martin Schöön) writes:

> First off: I am new here and this is my first post after
> lurking for quite some time.

Hi.

> Second off: I don't know much Python---yet.

It's not a very big language. If you have experience programming in
other languages, you can probably pick it up in a day or two.

> Problem: I have come across a small open source application
> that I find quite useful. It does have one major flaw though.
> Its output is in imperial units. Converting isn't a big deal
> for occasional use but if I start to use this stuff on a
> regular basis...
>
> So I down-loaded the source code and found this thing is written
> in Perl.
>
> Should I learn enough Perl to add the conversion? Probably
> but this may be a nice excuse to get my Python education
> going and if I do I might as well re-do the user interface.

Well you can always call it from Python via subprocess (which basically
wraps a shell and has fancy ways putting data in and extracting data
out).

> If I do re-write this thing in Python I might need to learn both
> Perl and Python...

You'll need to know one of them rather well and enough of the other to
get by. It's probably easier to know more Perl than Python since Perl
is a lot more expressive than Python (in the TMTOWTDI sense). Frankly I
learned Perl before Python and find it rather easy to go between the
two. YMMV.

> Hence, are there any Perl to Python converters? So far I
> have only found bridgekeeper which really is (was?) consultancy.
> Apart from that I only find people recommending a manual re-write.

It depends where the two languages vary from one another.

If the script your translating uses basic types or even simple classes
and typical control structures and operations then translating from one
to the other is a simple matter of copy-pasting the code and translating
the syntax and small bits of grammar.

However, in areas where there are high variations; you'll probably want
to stay away from it. Perl has a lot of freedom to manipulate
references and the programmer can modify the language to suit their
needs. So just be careful of code that uses these features as they are
difficult to translate into Python.

> Any thoughts/recommendations?

Depends:

- If you needed it done yesterday to get some work done, wrap the Perl
script in a subprocess and buy yourself some time to think it over.
- If your purpose is to learn Python, then start from scratch. Use the
Perl as a guide if there are any maths or algorithms you are unsure
about.
- If you're just hacking around to learn stuff, learn a little of both.
It will make you smarter if it doesn't confuse the heck out of you and
make you quit before you finish. ;)

>
> TIA,
>
> /Martin

HTH