Why Perl is not Python.
Perl has instructions that Python is more or less missing. Although you can probably sort out matching statements, the syntax will be so completely different from Perl that it makes it difficult to call it "translation". You really need to cook some Python fancy stuff to make it as concise as the original Perl.
Perl has run-time semantics that are so unlike Python that makes translation very difficult. Below we consider only one example.
Perl has data structures that are quite different from Python, which makes translation difficult.
Perl threads do not share default data. Only selected data items are available. Python threads have more common "shared" data.
One example from # 2 should be sufficient.
Perl:
do_something || die()
Where do_something is any instruction of any kind.
To automatically convert this to Python, you will need to wrap each expression || die() || die() in
try: python_version_of_do_something except OrdinaryStatementFailure, e: die() sys.exit()
Where is the more common wording
Perl
do_something
Would it with a simple - mindless - translation of the source
try: python_version_of_do_something except OrdinaryStatementFailure, e: pass
And of course,
Perl
do_this || do_that || die()
Even harder to translate to Python.
and
Perl
do_this && do_that || die()
really click on the envelope. My Perl is rusty, so I can’t remember the exact semantics of this kind of thing. But you must fully understand the semantics for developing a Pythonic implementation.
Python examples are not good Python. To write good , Python requires “thinking,” something automatic translation cannot do.
And each Perl construct must be “wrapped” in such a way as to get the original Perl semantics in the form of Pythonic.
Now do a similar analysis for each Perl function.
source share