Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Reading the answers to Python vs. Perl in ten years time here on SE, most people seem to say go with Python. I agree (sorry Perl fans ;-) ). I already know Python, and I think it is a very good language, sure, as any programming language it does come with its defects, but when I tried Perl I just didn't like it nearly as much as I liked Python.

I "know" C, Python, Java and Scheme and have toyed with several other languages. Now, is there any good reason for me to learn Perl? What is Perl "better" at than Python?

I do (hobby) application development and am learning some systems development as well (mostly programming for the Linux kernel).

I'm pretty sure Perl is not fundamentally enough different from what I know this far to broaden my mind too greatly either (I would probably do better by focusing on Haskell, Scala, Forth or something like that for that purpose).

share|improve this question

closed as not constructive by gnat, thorsten müller, Walter, GlenH7, Robert Harvey Nov 28 '12 at 19:04

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

15  
I'd suggest learning Perl if you get a job that requires you to maintain Perl scripts. –  FrustratedWithFormsDesigner Apr 4 '11 at 20:51
3  
And I'd suggest not learning Perl; just so that you have a valid excuse to refuse doing any job that requires maintaining Perl scripts. –  Brendan Nov 28 '12 at 7:28

9 Answers 9

up vote 19 down vote accepted

Ten years down the lane there will be a similar question 'Is there any good reason for someone who knows language X to learn Python' or 'What is Python 'better' at than language X'? In other words inside the hype cycle it looks like a particular technology may stay around for a long time. I will stop at that.

Since you've specifically asked whats Perl better at than Python, I will give you the following list.

  1. Text processing.
  2. Advanced Text processing of various sorts. Grammars etc.
  3. More power full syntactical constructs. Smart matching given-when loops, Devel::Declare, TIMTOWDI, filters etc.
  4. A very powerful object system like Moose(Moosex-Declare with sugar).
  5. CPAN.
  6. Community and resource like PerlMonks.
  7. Freedom, Power and Flexibility.
  8. Rapid pace of development. Nothing gets faster than Perl if you know it properly.
  9. Configuration over Convention.
  10. Powerful functional programming features.
  11. Quick, dirty scripting and prototyping.
  12. Heavy lifting jobs.
  13. Perl gets scoping better than Python.
  14. Doesn't break backwards compatibility.
  15. Nice web frameworks for cool kids.
  16. Terseness.
  17. Its faster.
  18. With best practices its hell lot better than Python due to the above features.
  19. Perl psychology.
  20. References.
  21. Recent advances like pluggable syntax keywords and 'static' keywords.

etc... etc.. the list will go on and on...

Python completely forces you to think in one way, Perl gives you the freedom to be what you are. By thinking in many ways, you ultimately start thinking of better ways of solving the problem. This helps in developing good programming acumen.

I'm both Python and Perl programmer. I still have not found how Python is better than Perl. Looks neat doesn't mean its neat

As Leo Tostoy said.

It is amazing how complete is the delusion that beauty is goodness.

http://en.wikiquote.org/wiki/Beauty

share|improve this answer
8  
Tolstoy was talking about human beings. In computer programming, beauty is goodness, period. With maintenance taking up far more of a program's lifecycle than creation/initial development, the ability to read code and decipher its intent is far more important than the ability to write code quickly, and Python (and just about anything else, with the possible exception of template-heavy C++) beats Perl hands-down in that regard. –  Mason Wheeler Apr 5 '11 at 3:33
4  
It depends on what sort of project you are in. For the sort of projects I work on. Automation, scripting and working quickly is very crucial. Loosing sleep about reading a program before writing it is the heights of premature optimization. Besides I follow the Perl best practices every time I write code so for me it doesn't matter at all. Python unfortunately fails to serve the above needs that I originally wrote. Don't get me wrong but I don't like using a wrong tool for the job. Can you tell me how to identify variable types without hungarian notation in Python? So much for readability! –  kamaal Apr 5 '11 at 3:38
3  
+1 for text processing, and code re-use via CPAN! –  user21007 Apr 5 '11 at 5:16
2  
@mason -- it really depends; perl gives you the ability to write very legible and maintainable code, on par with Ruby. It gets a bad wrap because a lot of the hackers that it attracted are the code golf types. –  red-dirt Apr 5 '11 at 10:38
2  
@I0b0 if Python helps your set of problems you must sure use it. As I have been saying its about selecting the right set of tools for the job. I use scripting for the reasons I mentioned above. If I wanted the features you mentioned I would rather use C++ and Java because they do the same more efficiently than Python. I see no logic in settling down for mediocrity that comes with Python for scripting. I use scripting for Power, Using Python for scripting defeats the whole purpose. If I had to move slowly with all that you mentioned, instead of scripting I would use static languages.Not Python. –  kamaal Apr 6 '11 at 3:55

As something of a Perl fan, learn it if you have an actual need to do something in Perl (your job is working with Perl or you have to work on a system with Perl and you can't install Python for some reason).

Other than that, yes, learn Haskell, Scala, Forth, or something else. There isn't enough new in Perl to make it worth learning.

share|improve this answer
5  
New as in different to Python, Perl probably did most of "it" first. –  Orbling Apr 5 '11 at 3:17
3  
are you Joking? There are no new things in Perl? When was the last time you checked up upon that? –  kamaal Apr 5 '11 at 4:15
    
It's also good to learn at least the basics of a language when you come across something you want to do, there is code out there that you can use to do 90% of the same thing, and will do 100% with tweaks. It's almost always easier to modify a working program than to build it afresh. –  user21007 Apr 5 '11 at 5:13
1  
@kamaal: Every so often, like when I upgrade to a new version. What I mean is that, if you know Python, Perl isn't different enough to be worth learning. It won't teach you enough to be worth it. –  David Thornley Apr 5 '11 at 14:09

Regular expressions!

All the rest is just syntactic sugar.

share|improve this answer

I know Perl, but I hadn't had any need to use any of my Perl knowledge for almost a decade now. For very long time Perl's niche was general purpose system/tools scripting language. But you can clearly see, that slowly, but steadily it's being replaced by Python in that role.

If I were you, I'd rather go for Scala, Ruby, Lua...


Edit: since my opinion about Perl loosing it's share is controversial to some of you, I'm including actual data. I know TIOBE might not be the best source for absolute values, but definitely shows the trends right. You also have to understand that it's not measure of amount software that exists, but rather measure interest in given language.

http://www.tiobe.com/index.php/paperinfo/tpci/Perl.html

share|improve this answer
1  
@Anto: Yes. That would be the essence of the answer. –  S.Lott Apr 4 '11 at 21:15
3  
@Aditya What market ratio are you speaking about? And as far as I have been hearing this Perl is dead stuff is going around for almost a decade now. By now 'Perl is dead' has become a Joke. And the way I see, there is nothing of Perl's class that can replace Perl. Ruby comes a little close, but Python isn't even in the competition. Not even close. Python will have to find other ways of attracting people than just going on about 'Perl is dead' for decades. As I said it before that has become a Joke. –  kamaal Apr 5 '11 at 4:45
5  
Tiobe? Really? I think you need to read upon the way they derive survey results before talking any further. –  kamaal Apr 5 '11 at 9:11
4  
@vartec - Tiobe puts Visual Basic on Top of JavaScript tiobe.com/index.php/content/paperinfo/tpci/index.html , How would you interpret that? JavaScript is Dying???? BTW, Perl has more solved problems than Python. There is a lesser need to ask questions. And unlike Python, Perl questions are asked across mailing lists, Perl Monks etc. Perl has a more diverse community when compared to Python. –  kamaal Apr 5 '11 at 9:25
3  
@vartec I don't wish to argue about a method which uses search engine keywords to measure programming language usage. Probably that's the reason why they ended up putting VB over JavaScript. That's the trend you are talking about? Whats more shocking is they put LOGO over SQL. It's like every time a school kid searches for his LOGO home work SQL dies a little. Which fundamentally has co relation. This survey isn't just wrong, but is wrong by real big factor. And every time a school kid searches for a picture of Python(snake) the popularity of Python programming language goes up. –  kamaal Apr 5 '11 at 9:45

I think Perl is probably a little faster to write quick and simple scripts than Python, just because there's less overhead and more useful defaults, e.g., it automatically reads from stdin or from the files on the command line, and you can use regexes much more easily. Personally, I don't find that enough reason to use both - I tend to get the syntax of the two languages confused, so I had to pick one and discard the other. For someone who doesn't have that issue, the facility for quick scripting might make it worthwhile to learn. Or might not.

Edit: Oh, and of course you might have to maintain some legacy code sometime. Lots of Perl code out there.

share|improve this answer

As a longtime Perl scripter who's switching over to Python, I find that Perl is still a lot more useful for command line use (for work that's a bit too complicated for the shell but not worth writing a complete Python or Perl script for).

For example, here's a bash + Perl one-liner to uppercase filenames in a directory:

for file in *; do mv $file $(echo $file | perl -pe 'tr/a-z/A-Z/;'); done

Or munge some XML from the command line (using Perl's regexes, which are definitely one of the strong points of the language), instead of writing a script:

perl -pi -e 's/^(<\/?testsuite)\b/$$1s/' testing/data/actual/report.xml
share|improve this answer
    
    
Hence "munge," not "parse." For a one-line munging of XML of known, specific format, there's nothing wrong with regexes. –  Josh Kelley Apr 4 '11 at 22:56
    
@Mason: in general, no, you cannot parse XML with regular expressions. But to make simple changes to a known set of files, a regex substitution is often sufficient. –  kevin cline Apr 4 '11 at 22:59
    
What's the point? Why do perl -pe 'tr/a-z/A-Z/;' if you can do tr a-z A-Z? Why do perl -pi -e 's/...' when you can do sed 's/...'? –  vartec Apr 5 '11 at 8:57
2  
If all one needed to do was such small scale replacements it was OK. But unfortunately most programs need some sort of if-else decision making post those s/// . sed and awk both become cumbersome. With C you have to bother with too much of low level details and with Python you have to bother about 10's of lines of objects, matching and exception handling for even a single regexp. Which leads to using only one option called 'Perl'. –  kamaal Apr 5 '11 at 10:07

What is Perl "better" at than Python?

"Better" is a very subjective term. Putting aside the whole dialog about "better" perhaps it would be more useful to detail some differences.

A few things Perl has the Python does not:

  • local keyword can make variables dynamically scoped
  • anonymous subroutines (Python's lambda is a gutted, wretched thing limited to expressions)
  • hash slicing (perhaps not that compelling, unless your used to using it)

These don't necessarily make Perl "better". They are just some additional tools that Python doesn't have which I have noticed. In some cases they are barely missed, in other cases you have to do some leg work to work around the missing feature. It should be pointed out that there are things which Python has which Perl does not. Again, it's mostly just different, not better (although Perl dereferencing is a syntactic atrocity and not so coincidentally, looks like an expletive).

Outside of the language the Perl community is very active. There are still many jobs out there for Perl programmers, and it's still heavily used in the bioinformatics space. It has tons of libraries. However, I'm not sure that any of these are compelling reasons if you already tried and found it not to your liking.

Disclosure: I am a fan of Perl and Python.

share|improve this answer
3  
The main difference is that you tell a Perl programmer what is missing from Perl, and he will add it to Perl. Tell a Python programmer what is missing, and he will tell you it isn't worth having. –  Brad Gilbert Jan 2 '12 at 1:38
1  
My experience with Python programmers is more that in approximately 2 weeks after the first of the alien flying saucers have landed, the Python community will have found a way to use Python to write apps for the alien computer system. –  Erik Reppen Nov 28 '12 at 6:08

To answer the main question title: yes, if you know python there are reasons to learn Perl.

Forget about what Perl can do better, the primary reason is to learn another language, another way of looking at things.

  • Outside of Perl, what other environment have you used that tried really hard to make your program run, no matter how much you screwed up the syntax?
  • Where can you have things such as automatic variables? ($_)
  • Where can you have a variable that depending on the caller could be completely different in one program? (my/local/global)
  • Where can you use a language whose parsing is equivalent to solving the halting problem?

Perl ecosystem has a different outlook on code and writing it. It is very much so get it working as quickly as possible.

I would say: learn Perl for scripting capabilities and for learning all the things that Perl does, that you should never ever do in other languages.

share|improve this answer
    
1. Not programming but HTML and ew. 2. JavaScript. 3. JavaScript. 4. Weird. That makes me want to learn Pearl. –  Erik Reppen Nov 28 '12 at 6:21

I would say as -

perl is multipurpose language while python is a OO language

share|improve this answer

protected by maple_shaft Nov 28 '12 at 11:57

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.