Question: When To Choose Python Over Perl (And Vice Versa)?
gravatar for Niek De Klein
6.0 years ago by
Niek De Klein2.4k
Niek De Klein2.4k wrote:

I have no experience with Perl and therefore always choose to use Python. So far I've heard that they're in basics the same and that a project being programmed in Perl or Python is usually decided what the group/person starting the project is most comfortable with. I am wondering what the ups and downs are for choosing one over the other.

For those that are proficient with both, why/when do you choose Python over Perl?

perl python comparison • 90k views
ADD COMMENTlink modified 5.6 years ago by Aditya Joshi30 • written 6.0 years ago by Niek De Klein2.4k

Perl for one-liners in a pipe. Python for everything else.

ADD REPLYlink written 6.0 years ago by Michael Schubert6.7k

Oh no! I anticipate a nearly religous battle with Perl-monks vs. Python-zealots.

ADD REPLYlink written 6.0 years ago by Michael Dondrup43k

There are probably specific cases where one is better than the other, but in my fairly general use, the overriding factor is to use the one your co-workers will be able to read.

ADD REPLYlink written 6.0 years ago by Tancata200

In commandlinefu, there are 27 commands tagged with python and 120 with perl - but "python -m SimpleHTTPServer" is the #2 best one-line command:

ADD REPLYlink written 6.0 years ago by Chris Penkett470

It sometimes depends on the packages/libs available for your purpose of each language.

ADD REPLYlink written 6.0 years ago by Boboppie500

@Michael Schubert I disagree. python -c enables command line access to python, and therefore makes perl completely irrelevant.

ADD REPLYlink written 6.0 years ago by mylons130

I know the -c flag, but with imports it gets cumbersome quickly.

ADD REPLYlink written 6.0 years ago by Michael Schubert6.7k

use strict; use warnings;

ADD REPLYlink written 6.0 years ago by Michael Dondrup43k
gravatar for Giovanni M Dall'Olio
6.0 years ago by
London, UK
Giovanni M Dall'Olio25k wrote:

When to use perl:

  • whenever you have to write a quick and dirty script that uses regular expressions or that executes system commands. Perl has been designed for automating operations on files and file systems; in fact, in perl to use regular expressions or to call system commands you don't need to import anything, while in python, you need to import a library to do these operations.
  • perl programmers usually adopt the Unix Philosophy of "Make one tool that does only one specific task". This is the reason why most perl script don't even include functions, not to speak of objects. Each perl script must be written in order to execute a single task, and then the scripts are piped together through the Unix piping system. However, consider that this approach can lead to a lot of confusion, and is generally difficult to mantain. Moreover, you can do "One tool one task" in python, too; the only difference is that you will have to import sys in every script.
  • whenever you need to use a library available only for perl. Have a look at the modules in CPAN. I think that BioPerl is still slightly more complete than BioPython, and that there are more bioinformatics-oriented modules for perl than for python (unfortunately). The Ensembl APIs are also available only for perl.

When to use python:

  • whenever you need to use the script more than once.
  • whenever there is a even remote possibility that one of your colleagues or someone else will ever use your script.
  • whenever you need to use functions or objects. As I was saying before, the majority of perl scripts don't even include functions, because they are more difficult to write than in python. For example, in perl, you need to learn how to pass the reference to a variable, etc.. and this leads to scripts that are more difficult to understand (in perl).
  • if this is the first programming language you are learning, I suggest you to start with Python. Python is much cleaner than Perl, and is designed to respect some good practices that any programmer should know. Have a look at the Python Zen for some ideas.

Edit after 5 years:

  • Python has now support for tabular-like data structure (data frames), which are very important for data analysts. Use Python or R whenever you have to work with tables
  • Python has now excellent support for machine learning algorithms and data analysis in general. Use Python or R whenever you need to do one of these things.
ADD COMMENTlink modified 11 months ago • written 6.0 years ago by Giovanni M Dall'Olio25k

Best explanation I've ever seen; you give concrete examples and explain both fairly.

ADD REPLYlink written 14 months ago by cwincomm0

Though we need to factor in that this answer was given 5 years ago.

Today there are even fewer reasons for using Perl - you'd be missing out many advancements and developments in other languages. Frankly, as much as I want to stay away from Perl vs X arguments I could not honestly recommend anyone to learn Perl as their first language.

ADD REPLYlink modified 14 months ago • written 14 months ago by Istvan Albert ♦♦ 74k

I agree. Nowadays it is more Python vs R rather than Perl.

ADD REPLYlink written 14 months ago by Giovanni M Dall'Olio25k
gravatar for Asaf
6.0 years ago by
Asaf4.5k wrote:

After about 5 years of using Perl I've moved to Python. I can't really think of something I can do in Perl but not in Python. Python, in my opinion, is much cleaner than Perl and have the great advantage of being object oriented. Building modules is much easier in Python hence the code you write is more reusable.

ADD COMMENTlink modified 6.0 years ago • written 6.0 years ago by Asaf4.5k
gravatar for Istvan Albert
6.0 years ago by
Istvan Albert ♦♦ 74k
University Park, USA
Istvan Albert ♦♦ 74k wrote:

I think very few people are completely agnostic about programming languages especially when it comes to languages with very similar strengths and weaknesses like: perl/python/ruby - therefore there is no general reason for using one language vs the other. 

It is more common to find someone equally proficient in C and perl, than say equally proficient in perl and python. My guess would be that complementary languages require complementary skill sets that occupy different parts of the brain, whereas similar concepts will clash more easily.

ADD COMMENTlink modified 3.4 years ago • written 6.0 years ago by Istvan Albert ♦♦ 74k
gravatar for Michael Dondrup
6.0 years ago by
Bergen, Norway
Michael Dondrup43k wrote:

You are totally correct with your initial assumption. This question is similar to choosing between Spanish and English, which language to choose? Well if you go to Spain,...

All (programming) languages are equal, in the sense of that you can solve the same class of problems with them. Once you know one language, you can easily learn all imperative languages. Use the language that you already master or that suits your style. Both (Perl & Python) are interpreted languages and have their merits. Both have extensive Bio-libraries, and both have large archives of contributed packages.

An important criterion to decide is the availability of rich, stable, and well maintained libraries. Choose the language that provides the library you need. For example, if you want to program web-services (using SOAP not web-sites), you better use Java or maybe C#.

Conclusion: it does no harm to learn new languages. And no flame wars please.

ADD COMMENTlink modified 6.0 years ago • written 6.0 years ago by Michael Dondrup43k
gravatar for Andrew W
6.0 years ago by
Andrew W290
Andrew W290 wrote:

Python forces you to write cleaner code and gets you thinking about objects from the beginning, which should make the transition to object-oriented coding easier. If someone is new to programming, Python is likely the better choice. But that doesn't mean people, especially beginners, will automatically write code that can be easily understood by others. Perl only makes it easier for people to write confusing code.

If someone is already a competent Perl programmer, I don't think there's any overwhelming reason to switch. Most employers will understand that someone competent in one of those languages will quickly pick up the other. The time may be better invested learning Java or R scripting.

ADD COMMENTlink modified 6.0 years ago • written 6.0 years ago by Andrew W290

Last time I checked it didn't force you to write OO.

ADD REPLYlink written 6.0 years ago by Michael Schubert6.7k

Thanks, my mistake. I've updated with a more accurate statement.

ADD REPLYlink written 6.0 years ago by Andrew W290

use strict; use warnings;

ADD REPLYlink written 6.0 years ago by Michael Dondrup43k
gravatar for John Kern
6.0 years ago by
John Kern50
United States
John Kern50 wrote:


Like bioinformatics, many other areas share the problem of dealing with "big data" and Data Mining. In industry and computer science, Python (and Java) is more common than Perl in these areas. You may find programming in Python beneficial because you would be able to leverage the work and infrastructure of others in related fields.

-HTH John

ADD COMMENTlink written 6.0 years ago by John Kern50
gravatar for Aditya Joshi
5.9 years ago by
Aditya Joshi30
Aditya Joshi30 wrote:

Hi ! Here's a list of few areas which are important from point of view of Bioprogramming and the winner among Perl and Python in each :-

1) Ease of programming : Python[?] 2) Regex use and speed of execution of engine : Perl (Python will soon catch up with its 3.x)[?] 3) Bio* packages : Are available for both for Python and Perl, though here Python is the clear winner due to its inherent OOP philosophy.[?] 4) Syntax : Python any day (God, I don't know why people use Pseudocode when there's Python!). a geek joke says : "Perl is the only language whose code looks same before and after RSA encryption"[?] 5) Wrappers : Python has excellent SWIG wrappers for cross-language implementation of code. All popluar languages : C, Java and .NET have a combined distro with Python (Cython, Jython, IronPython etc.)[?] 6) Web programming : Ah! Here comes the most useful thing for Bioprogrammers, Perl CGI or Python ? With almost all bioinformatics knowledge housed in online biological databases, and with computing done by online tools, the choice of language for this one is important. I am once again not being biased towards Python, but apart from CGI functionality in both, Python's web frameworks are better than that of Perl (google these : web2py, Django etc). With these the development time gets reduced to half. Also, Python has an enhanced functionality in the form of ModPython and its even faster relative : ModPython Publisher. It gives performance as fast as PHP and even a C-CGI code.[?]

ADD COMMENTlink written 5.9 years ago by Aditya Joshi30
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 945 users visited in the last hour