62

Okay, so I'm finally making the jump into scripting languages and I have decided to focus on either Python or Perl. The problem is: I don't know which to cut my teeth on.

Most of my programming experience is in C, Java, and C++. There's no specific task I would be learning Python/Perl for, other that possibly applying it to my dev work to make life easier in general.

What do you think? Which do you use? Is one more industry relevant than another?

165

There's an awful lot of FUD here about Perl. One thing I've noticed is that Python folks seem to have a bit of a thing for bashing Perl, but you won't see that so much in reverse. The insistence that you can't write maintainable Perl is pure bullshit. Maintainable code comes from good developers following good development practices, and that can be done (or not done) in any language.

As a Perl guy myself, I have nothing against Python. It seems like a pretty good language with a strong community.

Both Perl and Python are fairly mature and featureful languages. I think Perl's CPAN beats Python's libraries by a fair bit, but OTOH Python has way more standard libraries, so you don't need to go looking for 3rd party libraries as often. Also, CPAN's expansiveness is a downside, as there's often many overlapping libraries for a given task, making finding the best one harder.

I'm surprised you didn't mention Ruby. I think it's another worthy language. It's less mature than either Python or Perl, and definitely slower, but it's got a lot of pluses too, including being "truly OO" in a way that Python isn't (and Perl isn't even trying for).

FWIW, if you're interested in Perl I'd strongly recommend checking out some of Perl's highlights on CPAN, including Moose, DBIx::Class, DateTime, etc. Of course, Python and Ruby also have particularly excellent packages that people will point to, like Rails, Twisted, Django, etc.

Disclaimer: I'm a Moose core dev and the creator of DateTime. But they do rock, and I know lots of people in the Perl community agree.

This actually gets to a secondary point. A language is much, much more than its syntax. In fact, syntax is the least of what makes a language. It's an ecosystem, and to truly appreciate a language you also have to take some time to learn about that ecosystem. Perl has a really amazing ecosystem and community. I bet Python does too.

To a large degree, you need to find the tool that fits your brain best. Perl and Python can do basically the same things, but they do them differently. Try both out (and try Ruby) and see which one works for you.

76

I have used both languages professionally and for fun.

I learned Perl around 2000-ish, and was a big fan for many years. I had never used a dynamic language before and was really impressed with how much more effectively and quickly I could write working code, compared to C.

Around 2002-3, I started to hear about Python a lot and glanced at it... the whole "significant whitespace" and strict type checking thing turned me off and I purposely ignored it for several more years. Eventually I found my Perl code was getting really unmaintainable, and seriously took up Python. I've never looked back. Python is basically dynamic language done right. One of the best things about it is that the standard library is extremely versatile (database, XML, JSON, math, etc.) and all those modules have a common interface and feel, which makes them easier to learn and use.

Eventually, Perl just got to be too much of a mess, I'm afraid. It's not really Perl's fault. They kind of made Perl up as it went along. No one knew what a dynamic language "should" look like or do when Perl was first released (pre-1990, I think). So it's got a lot of things oddly bolted-on, like variable scoping, file handles, and a very messy object-oriented system.

Perl 6 is supposed to be a lot cleaner but no less expressive. But it's taking yeaaaars for it to be ready. Why wait? Python's ready now and the much-anticipated 3.0 release is in beta.

PS- Perl's CPAN is indeed a very nice feature. Python has the Python Package Index (aka Cheese Shop) which is more or less the same thing. All ya gotta do is "easy_install packagename" to download, build, and install from it.

73

There are so many people praising Python here that I think I have to put a bit of counterweight here. :)

Maybe I'm a bit biased because I've been coding in Perl for so long, but I think this also allows me to give a better insight into the language. Many people are frightened of Perl because they saw a cryptic one-liner and think to know that Python is "cleaner". Here's what I think.

As some people already mentioned, Python is a very verbose language. It forces you to indent correctly. This doesn't mean that you can't indent Perl code nicely too, it just means that Perl still works if you don't. Pythons verbosity also makes single pieces of code more understandable. However, if you look at bigger Python applications, you'll find that being force to write simple things with much code distracts from the real important things. If you know Perl well, you'll thank God for the possibility to put simple things away in two lines or three or even a one-liner and put the spotlight on the important things, like business logic, which you're free to write as verbose as you feel like. If you know a natural language, one line of text is more understandable than 20 lines, saying the same thing, isn't it?

Perl is surely harder to learn than Python. And it takes longer to learn. After years of using it every day I still find cool features sometimes that I didn't know before, and that I absolutely love. It's a bit like Vim. ;)

Some people also claim that the Python community is more active and develop more cool new things. That's surely true. Perl people don't develop cool new things, because they've been developed years ago and are available from CPAN, ready to use.

To make things short: Python forces you to do things. Perl allows you to do things your way. You will do lots of errors in the beginning, because Perl doesn't say "do it this way, or it won't work!". While Python will make it easy for you in the beginning, Perl will allow you to be effective in the end. Plus (and this is why I love Perl so much), when you become better, you'll learn to love the freedom to express yourself with your code. Code is just art, after all.

53
Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>> 

I'm a python guy personally. But I still need to give tons of credit to Perl. It runs just as much of the internet as apache and 2/3 of every data center. The CPAN has 12 different ways to do anything. And Perl people are just plain nice.

The people that say Perl is hard to read are being silly. The Perl they tried to read may have been hard, but I've paged through tons of Perl that was more readable than the python I write.

I think pythons major advantages are its interactive interpreter and docstrings (which can be easily printed from inside the interpreter), but for quick hacks on files, perl.perl.perl.

41

What are you gonna put your trust in?

alt text

(Disclaimer: I have nothing against neither. Just seemed a catchy line.)

24

Now that I'm done reading all the comments about how Perl is unmaintainable, write-only, and doesn't do OO, I suppose I could argue against them, but I've spent enough time screwing around on stackoverflow already. I really should get back to updating the Employee class to add new features that have been requested on the Perl web app I wrote last year and haven't looked at since. There's a little bit of a ramp-up time on getting back into a project that old, of course, since I no longer remember what I did back then, but it's perfectly clear once I look at the code.

If you already have good programming habits (as I did from many years of other languages before getting into Perl), there is nothing to fear from Perl.

24

I've tried Perl, Python, and Ruby. (I've taken a look at Neko, and groovy and beanshell, too.)

I started out in Perl. I learned enough to start using the "black magic" of source filters, symbol table manipulations, B and AUTOLOAD. Then I began to hear some complaints and comparisons from the Python crowd.

Then I noticed some of the same dissatisfactions I had with Perl echoed in Python enthusiasts. This turned into frustration with the idea that there really are too many ways to do it in Perl.

Python is touted as more aesthetic, but that's only true if you don't find yourself deep-diving and using the __<foo>__ methods and variables too often. There is no definite gain in aesthetics using num.__rmul__( otherNum ).

Python turned out to be no where near as "intuitive" as billed. And although, Python remains a acceptable language, I think the hype ended up influencing my decision to move on.

I met ex-Python rubyists bagging on Python much the same way that Python enthusiasts bag on Perl. So it only seemed justified in subjecting Python to the scrutiny upon it that they, as a body it seems, subject Perl to.

Ruby is more aesthetic in almost all syntax, and I found it to be a little more "intuitive". (Sigils have never bothered me.) But as mentioned above, Ruby is still rather slow outside of JRuby. I also don't like the sometimes arbitrary non-OO syntax in modules. Instead of using the behind-the-scenes names for the overloaded operators, you defined the operator itself.

Perl 6 will have something that Python and Ruby do not yet have, and that is the ability to invent operators. I have already played with this in pugs, and it's one of the things that can be afforded with having a language that understands grammars.

But the harshest criticism that can be leveled at Perl 6 is that it is practically "vaporware". Outside of that, though, enhancements for Perl 5 look to what has been codified for Perl 6 to include.

And the flexibility of Perl seems to suggest itself again. Perl Best Practices takes place of rigid rules about the best way to code. And where as Perl presented a daunting variety of OO paradigms, Moose is informally becoming the way to do OO.

20

My two cents: I used to do a lot of coding in Perl, and now I do a lot of coding in Python. I am happy with this change. Personally, I find Python syntax much easier to read, and the core concepts easier to grasp. After years of Perl coding I still couldn't imagine getting much done without reaching for the camel book, and with Python the concepts seem to stick, although maybe that's just me. Here are some specifics on why I prefer Python:

  • Python scales up more easily than Perl. That is, if your project is going to grow beyond much more than a single script, Python makes that kind of organization a lot easier. As others have pointed out, good design is entirely possible with Perl, but in Python it's easier.
  • Python has better high-level data structures than Perl. I'm sorry, it just does. Perl has hashes and lists just like Python does, but combining them in Python is so much simpler than in Perl that it's not even funny. Perl's references are a cruel joke by comparison. As a programmer in a high-level language, these data structures are my bread and butter. This difference alone is enough to make me prefer Python over Perl.
  • Syntax matters. Readability matters. If you program in Perl long enough, you won't even need to look up things like $" and $/ and $* and @F and $^O and on and on and on. But you know what's even better than knowing them by heart? Never having to learn them. This is a trite criticism of Perl, I know, but it's still true. Whale guts, line noise, whatever you want to call it -- Perl has it, Python doesn't.
  • If you care about OO, then Python wins. This goes along with what I was saying earlier about Python scaling up more easily than Perl.
  • Python has Jython and IronPython, which are really nice if you use Java or .NET. I think Perl has some Java and/or .NET implementations, but I don't know if they are well supported. I kind of doubt it. Jython itself has only recently awoken from hibernation.
  • Perl's contexts are bizarre, confusing, and unnecessary. This is just a poor design decision, in my opinion.

I must admit that Perl has a few advantages, too. Here are some of them:

  • Perl's regex syntax is really nice. It's the best I know of.
  • Some have mentioned that Perl has a faster interpreter. I'll take their word for it. This has not been an issue in my projects, but it may be one in yours.
  • If you want to pump your shell scripts up on steroids, Perl may be a more direct translation than Python.
  • Python has a better standard library, but Perl has a better nonstandard library. CPAN is pretty awesome, whereas Python's package management is... um, lacking by comparison. I've seen others say the opposite, so maybe it's just me, but my experience has definitely been smoother with Perl in this area.

If Perl 6 weren't vaporware, then that would be something else to consider in favor of (a future version of) Perl. But the onus is on Perl at this point to show us that this is not true.

19

Perl is a fairly poor language to learn. Don't get me wrong - I like the language, and use it quite a bit. But for learning... Oh dear, where to start?

  • There's always more than one way to do something. Usually dozens. And many of them - quite frankly - are very bad ways to do it. As a new user not only is this complexity confusing, but you probably won't be able to figure out the hidden pitfalls until too late.
  • Perl has a confusing, cryptic, and very dense syntax. In the hands of an expert this allows for extremely powerful scripts to be written that fit into a line or two with a minimum of typing. For a novice, however, you may spend hours puzzling over some overly-clever trick in an example.
  • Perl doesn't enforce good habits. That's part of the attraction - you can do anything. This includes writing clear documented code adhering to good programming practices. It also includes writing absolutely unmaintainable "write-once read-never" code.

Python is just as powerful, but the syntax is much cleaner, and - I realize this is absolutely subjective - it's a bit harder to abuse. For example, the whitespace rules mean that you HAVE to indent and structure your code at least slightly sensibly, which is - frankly - a pretty good thing to enforce, especially when learning. Learning good habits early pays off. :-)

In short, while Perl is a great language, for learning, I'd recommend Python. (Ruby would also be a decent choice.)

18

Learn Perl.

They say the richness of a language is in its abstracts. Perl has plenty. Expressiveness is a good thing.

The techniques I learned almost 10 years ago are just now finding their way into other languages that purport to be so much more modern. A language that clobbers you over the head with the "YOU WILL DO EVERYTHING IN OO" or "YOU WILL INDENT 4 SPACES" two-by-fours are asking to be replaced by the next big paradigm.

Perl is post-modern, and will always be up-to-date, because it does things your way, rather than forcing you to do things its way. As your way changes, Perl will change with you. Perl6 only adds to this strength, making Perl6 more Perl than Perl5 is now.

17

I use perl and never learned python. But I come from a background of shell scripting with awk/grep, and C/C++. That made perl just far too easy to pick up, as it has nearly all the power of all that came before, and ties it together really simply.

So, it's really hard to answer without a lot more context: do you have any perl/python tooling/programmers available to you at work?
Perlmonks.org, for example, is great as a language-specific site, though it's still better to have someone to talk with right in front of you instead of waiting for responses.

What do you want to accomplish?
I know you said you don't have a specific task, but I have always found it easier to pick up new skills by having a target in mind. I had little mini-projects that helped me learn C, C++, STL, Perl, and just recently SQL. They make it fun to learn, and anything fun is easier.

So find a project that makes sense for what you're learning, and try it. The questions you come up with from there will propel you into whichever language you're learning.

15

On the technical level I would weight those two languages as more or less equal. But my bet is still with Perl - because of CPAN. It is experiment on the joint between technical, social and political and I think it have got a lot of balance right - and as show all the other attempts this is not an easy thing.

13

I've been developing software professionally for about 30 years. Python's far and away my favorite language.

It was remarkably easy to learn (it took me about 2 hours from installing it on my laptop to having a working program that did Markov-chain-based gibberish generation, which is usually the first thing I try when I pick up a programming language). The elegance (and thoroughness) with which fundamental data structures like sequences and dictionaries are integrated into the language is not only intellectually appealing, it also gives the language a kind of self-similarity that makes understanding it come quickly.

I wanted to like Perl. Really I did. I put a great deal of effort into it, because at the time (about 5 years ago), I desperately needed a decent language for writing utility programs. But I just never got it. I never got over the sense that what I was trying to use was a grab-bag of mostly-unrelated good ideas that had been bolted together over many years into a sort of lumpy, awkward whole. I put at least as much time and effort into learning and using Perl as I have into learning and using Python, and I never got to the point where I felt really grounded in the language.

There's certainly stuff that's not pretty in Python. (I mean, name mangling? Really, Guido? Really?) But if Perl has the kind of self-similarity and internal consistency that makes Python so easy to learn, it's well-hidden.

7

I really like Perl, after using it for a few years. It's really powerful, especially for text processing. It has a really strong set of libraries available through CPAN. It is a little quirky however, and Perl 6 is going to change things a lot. Perl 5 however is very solid and proven.

Python, however, I don't have a lot of experience in, but I suspect that it is the better language to learn today as it gains popularity.

6

I've used Perl for several years, and have looked at Python a little but never really learned it. I'll offer a few random thoughts about Perl:

  • As others have said, Perl is a quirky language; personally, that's one of the things I like about it.
  • Because there's more than one way to do it, Perl is harder to learn than some languages. However, since you have a background in C, you shouldn't have trouble learning a way to do what you need.
  • Structurally, Perl is more C-like than Python is, from what I've seen. From syntax to curly braces to use of whitespace, Perl will probably feel more comfortable to a C/Java programmer.
  • Perl is not an object-oriented language. You can use Perl modules to do OO-like stuff, but Perl's object model is nowhere nearly as comprehensive as Java's.
  • Perl is so flexible that it's easy to get started with a subset of the language, and learn additional functionality later.

That last point is the most important, IMO. I spent nearly a year writing small scripts before I even knew what a hash was; after learning about hashes, I had a better way to handle data. It was more than a year before I tried regular expressions; after I learned them, I had a better way to process strings. I didn't understand how to use modules as objects until several years later; but when I did, I had a better way to organize my data. I've programmed with Perl off and on for over six years, and there are still features I haven't even looked at. As I learn them, my productivity will probably improve, but I am still able to get things done at my current level.

"There is more than one way to do it" allows programmers to advance at their own pace and comfort level. You might have a completely different way of solving problems than I do, and that might make your Perl code look cryptic to me, and vice versa. (That's probably the main reason Perl is so often criticized as being unreadable.) But Perl's flexibility puts the programmer in charge of how things get done.

5

I agree that Python is the langauge of today and might be better but I would also consider the environment you work in.

In my case Perl is common on all our servers and it's not always easy to get Python installed. Also, most people in my organization know perl and not python so if someone needs to give me a hand or maintain a program when I'm on vacation again Perl will be the better choice.

5

Compromise: learn Ruby. Ruby has a strong Perl heritage, with much of Perl's syntax and conveniences. While it is not as inspired by Python, it shares with Python a strong emphasis on Object-Oriented style.

5

I've tried very hard to stay objective about this in the past year or so.

For the kinds of things I'm interested in, there are only 3 serious language choices: Perl, Python, Ruby. I need something that's fast and flexible, and has a large user-supported library of software. I discard Ruby as most people already have Perl or Python installed and I'd rather not add another dependency.

Perl is less verbose. You can cram a lot of logic into a small number of characters. This is both a blessing and a curse. I find some of Perl's shortcuts to be extremely useful... especially the easy shorthands for running a regular expression on a file, or operations like checking if a file exists. The result of this is that you can, if you choose, end up with very concise scripts. One downside is that there are less clues as to what is going on in a script for those who don't know the shortcuts.

Python is more typing. I don't consider this a negative. I'm convinced that syntactically significant whitespace is a red herring and shouldn't be a serious mark for or against the language. I've thought it was significant in the past, but I was wrong. Don't judge either language on its syntax except as a means to determine which you find more aesthetically pleasing. I find Python more aesthetically pleasing at the moment. In 4 months I could change my mind.

If you're doing anything relatively object oriented, I'd recommend Python. I haven't looked at Perl's implementation in a while, but I remember it being messy and overly complex. I'm not convinced that Python's implementation is all that great, but it's ridiculously simple.

Aside from that the languages are about equal in every sense that matters. Use the one you like better. Neither language is as good as their respective pundits claim, but they can both be very useful tools in the right context.

One minor concern: using Python with other developers may force you to get your collective heads out of your asses and agree on a standard whitespace format. If you don't have one, you need one. It's important, and not just for Python... for the general sanity of all your programmers.

3

I don't use either, but in my dabbling with both, I've found Python to be a language that makes a lot more sense to me.

Perl is a good language, but Python is definitely the fad language of today.

3

For humor, I refer you to: http://scott.yang.id.au/2003/08/python-vs-perl-according-to-yoda/

Both languages are used in a large number of scenarios. Perl is quite popular as a config and control language in IT departments. However, Python is used by many companies for prototyping larger applications, and optimizing their apps w/ C/C++ later. Google is an example of such a company.

Personally, i find Python intuitive, and while I code in .Net, my love and my easiest learning is w/ python. If you need something to cut out the syntactic cruft so you can think about problems, go with python.

3

Reach for Perl under these conditions:

  • Memory use is critical
  • Low IO overhead is required (i.e. ? many, many text files are being parsed)

Reach for Python under these conditions:

  • You need something that processes quickly (but isn?t memory intensive)
    • On the average, Python and Perl are neck & neck here. If you have more experience w/Perl, go for Perl. If you need something readable, go for Python.
  • You have an OOP OCD
  • You don?t know Perl, and you have some hefty processing to do (that isn?t memory intensive)
  • You?re making the step from static HTML to dynamic web pages cough, and you have a CS degree
3

I recommend Python: it may be my favourite language. It supports both OO and functional programming: you can do mind-blowing things in comparison to Java. Also, it is quite readable, has a rich library set, and has a sense of aesthetic in the community (called Pythonic).

As for use in industry, it is used by some major players: e.g. it is one of the few languages approved for use at Google. That said, Perl is probably used by more companies, as it was huge for years.

You didn't ask, but I would suggest Ruby and Groovy as other candidates. Ruby versus Python is a true dilemma (I've blogged that this is like choosing between a Porsche and a Ferrari). Groovy's advantage is that the syntax is similar to Java and you can use the familiar Java libraries; however, if you want something truly new, that might be a drawback.

3

If you want same readability in Perl as in Python, use perltidy from CPAN - you will get it automatically instead of doing it manually in Python.

If you want to get a job read this comparison: Perl, Php, Python and Ruby: Whats More Popular in the Corporate World

2

Python is quickly replacing perl for many as their language of choice. But that's partly because perl went for a very long time without a major update. I've heard that perl 6 could change this some. But I think I'd still go python.

2

As a Perl fan, here's a few points:

If you know C and Unix, Perl will probably be a bit easier to get started with.

Perl has really good library support.

Perl's great for short scripts. I never write anything in bash any more.

You can get both Perl and Python on any platform you're likely to be computing on, but Perl is perhaps a touch more likely to already be there. (The downside to this is that the system Perl is more likely to change versions out from under you - happened on AIX once, and a badly written Perl program simply stopped running.) However, Python is more easily rewritten to sit on different platforms. I don't know of Perl analogs to Jython and IronPython (JVM and Microsoft's CLR respectively).

2

There's no specific task I would be learning Python/Perl for, other that possibly applying it to my dev work to make life easier in general.

Oh, ABSOLUTELY choose Python over Perl. Perl was the first scripting language I picked up back in the days when PHP was barely invented and while I loved the way it made certain thing so much easier than in C/C++, it also possessed so much obtuse syntax that tripped me up endlessly. When PHP came about, I ditched Perl without a second thought. After PHP, I learned Python and loved it so much that I try to use it in lieu of PHP for web tasks whenever possible (setting up server environments for Python-run websites can be a bit more involved compared to PHP).

For everyday problems that pop up which require programming to address, as well as for in-house auxiliary tools, Python is our #1 tool of choice due to the speed of development and maintainability. Things just get done so much faster and with much less pain when using Python.

Perl's unique feature of being extremely concise means that it will always have niche applications where it is the best language to use (being a Python fan, I would say might be better in certain niche situations than Python, but not by much) and is probably why it is still around, however you did say you were looking for a language that you can "apply to dev work to make life easier in general" and Python absolutely fits the bill here.

2

I know many programming languages. I love Perl. It is powerful and is doing the job well. But I would NOT recommend Perl as a starting programming language for a beginner. Perl tendency to be forgiven plus the freedom it gives you might be more of a problem that a feature to newcomers. In plain words, as a beginner you will have a bigger chance of developing bad programming habits in Perl than probably in Python. On the other hand, once you have good programming habits and you manage to develop your own programming style, you might find Python syntax almost impossible. You know how and when to indent, you don't need a language to tell you that. This is the main reason for why I could never move more deeply into Python. So if you are a good programmer with a solid programming discipline I would recommend Perl.

1

Python is more verbose, and by extension more easy to maintain.

Perl is very concise, and very quick to do useful tasks with. But it is more suitable for throwaway code rather than maintainable systems.

1

Python for sure. Perl is great for quick scripts that you will never look at again. iPython alone is more than reason enough to learn Python: http://ipython.scipy.org/moin/.

iPython allows you to examine any object by using tab complete (ala the unix command line) which makes experimentation super fast and fun.

1

Guess it would be unfair to say you'd be better to learn both of them. Since I use both of them for work and for pleasure, I'll start with one major advantage of each:

  • Perl - Regular expressions. Most definitely the best language for quick text edits, string replacements, etc. After learning regexs in Perl, you'll understand it much better in other languages.

  • Python - Super quick modeling. Python could be useful to complete a task you're used to in C++/Java, in half of the amount of code (estimate), and 1/10th of the time (estimate). Sometime you'll stick with the Python result, and won't bother implementing it in a lower level language, since it's just good enough.

If you're doing more administrative tasks than other tasks - Perl it is. If not, and you have time for only one of them - Python.

Also, keep in mind that Perl's syntax is very much like C and Java, while Python is a whole different thing. Adding it to your resume would be a bigger plus than adding Perl.

Final note (don't want flame wars): every thing said is my humble opinion only.

1

Well I find it a matter of taste. I've looked a bit at Perl wasn't all that happy with what I saw, I looked at Python and wasn't all that happy with what I saw.

However that's just me. Others have made good points for Perl, so be it. It's not useful to ask X vs Y; this is just asking for trouble. See the vi vs. Emacs stuff, Windows vs Linux and what all comes along.

One has to clearly admit that both Perl and Python are not just languages, but eco-systems. Both have unbelievable many libraries. CPAN can be named legend for packaging.

However there are few things where you do not have the choice. Let's take OpenOffice automation you can use C++, Java, JavaScript and Python. I do not have heard of any other languages in the UNO area. IIRC there is a Python on .NET but I can not remember having heard of a Perl there. I guess there are a few other areas where it's not Python vs. Perl. Let's look e.g at Debian, Perl is mandatory, you can not escape it. It's a base tool, that's not true for Python.

I'd argue that Perl is a very good match for the Unix tool chain, but Python is not far behind.

If you have the choice, choose what you like more. But if you know both, you definitly have more choices, and sometimes you have to know the other.

I for my part have choosen not to use either of them. My answer currently is neither Perl nor Python....

Regards

1

Both are generic very high-level languages, with healthy ecosystems, sound methodologies and proven performance and reliability. There are good reasons to know both- Perl is a ubiquitous part of the web, Python is used in many important places (e.g. Google Apps). Humbly, here's my opinion:

Perl distinguishes itself by being astonishingly diagonal: there are a dozen ways to do any one thing. I think studying Perl could help one think about problems from different perspectives, it opens your mind to alternative approaches to one problem.

Python distinguishes itself by being extremely well designed and usable. It's easy to learn, has extremely intelligent design choices, and is an effective way to quickly build very usable projects.

Given your interest in making your development life easier, I'd recommend giving Perl a go. I consider it further from C/C++/Java than Python, and therefore it affords more opportunity to see things from a different perspective (which I feel is very valuable). It's also a glue language, and can be used everywhere for quickly solving problems.

0

Both are good languages, but if you only start learning one of them now, go for Python. It currently has much more boost behind it, and much more new and cool stuff is being developed in Python than in Perl. By choosing Python, you're not missing anything because it can do anything Perl can do.

If you have specific application needs, specify them - because then the answer may change. Otherwise, just download the Python distribution relevant to your platform and read the tutorial.

0

Perl is also in a weird state of flux between versions. Perl 5 is heavily used, and Perl 6 has been in development since Larry Wall announced it in 2000! Perl 6 looks VERY different and I can't imagine an upgrade path will be painless once it finally arrives.

On the other hand, Python has been on a very defined path for Python 3.0 and we will see a release shortly.

0
  • Python encourages code readability and maintainability. The significant white-space also appeals to my inner copy editor. Perl requires that you discipline yourself, or be satisfied with write-only code.

  • The Python standard library is excellent and, for the most part, well-documented. I don't remember how well Perl stacks up here. I do sometimes miss Perl's easy regexp handling.

  • Python has the Python Package Index. The widespread adoption of setuptools and easy_install as the package-management tools of choice, along with environment/dependency tools like virtual-env and zc.buildout, make for a powerful and comprehensive development, testing, and deployment system. I always found Perl's CPAN just barely comprehensible, often leaving me on the verge of tears as yet another dependency noisily failed to install.

0

I haven't deeply looked into Python, but I've been into Perl for two years (a begginer). My points:
* Perl is not a difficult language. On the contrary, it's pretty easy.
* Perl is powerful. I'm still being surprised how easy some things are done, in the style of

variable =~ s/'/"/g;


I only wish that Python was so easy.

0

I am a scripting newbie although I've programmed in C/C++/F90 on parallel machines for several years (yes, a button pushing fluid dynamicist now benchmarking supercomputing applications). Very recently, I decided that I had enough of typing job scripts by hand (you know, you ask for 32768 cores and when the job finally starts after queuing up for a week, it crashes because of a blunder in the run script - very frustrating to say the least).

So I decided to write my scripts. It basically involves copying from a template directory and changing a few things here and there, diving into the input files. The biggest hurdle that I found was not so much difficulties in learning perl or python - they're both VERY easy languages, coming from a background of C/C++/F90/F77 and will get the job done.

But I find that with perl you can get the job done very quickly, from zero to productive user in 10 min - all that you need to know are $_s, variable declarations, a bit of regexing, etc. However, I've always found python much more daunting (been trying to learn it for a few years, but put it off) to write code on because there's just so much baggage - the strips, joins, import os.blah.bleh.foobar, self.glorification, etc

That being said, I got my scripts done using both perl and python. Python is of course, very easy to read (code is not too hard to read anyway, its only getting productive writing it that is problematic). I'd give a thumb's up for perl to start with - it's not only easy, but it can make you productive in no time, with so much less verbose manual BS. I won't bother about unreadable code and all that, at least not while getting started. It's never so bad, generally speaking (and the codes around don't really look all that unreadable anyway). I definitely find perl much more fun than python.

-1

Perl, the language, is a mess. But perl, the interpreter/VM, has an edge over python in that it is stackless (the language's calling stack doesn't use the system stack). As a result of this, Perl can do real shared memory threads while Python cannot. There is a stackless python but it is experimental, not in the mainline source.

That is the most significant technical difference, and might not even matter that much anyway. Everything else is subjective, and a matter of personnal preference:

  • Perl has more libraries; Python has better ones. Edit: Perl's are more mature. For instance many Python programs at this time can't do SSL through HTTP CONNECT on a proxy.

  • More people know Perl; Python is used on more projects.

  • Perl has more documentation; Python's more usable.

  • Perl is installed on almost every *nix system; Python is a central part (system scripts, configuration dialogs) of most Linux/BSD distribs.

  • You can find third-party Perl APIs to almost anything; almost everything provides Python APIs.

Disclaimer: YAPH.

-2

Perl has a much easier regular expression mechanism to use and has been around for a while, having more mindshare and libraries.

Python is better for software engineering.

-2

Perl is fine if you use it regularly (e.g. at work). If you don't, it's just too hard to remember the syntax, there's a fair amount of magic characters in it to make the code unreadable if you don't use the language often enough.

If you do use the language regularly, it is a good choice. It allows you to write very dense/concise code, and perl gives you the freedom to do things the way you want to do them.

-3

Interesting :

-3

If you want to do anything with threads, memory mappings, objects (classes), or XML/SGML/HTML parsing ... Python will be far easier to learn and far more robust.

If you might need introspection or any sort of object serialization Python will provide it easily.

Spend 15 minutes with ipython (the "interactive Python shell" --- which is written in Python as a wrapper around the default Python interactive shell) and compare that to a Perl debugging session. (ipython is not part of the standard Python distribution; but the standard readline and rlcompleter modules gives you most of the features, without the ncurses color support. ipython just makes it prettier and even more convenient to try your code snippets interactively).

Read up on the multiprocessing module that's been added to Python 2.6 and pay particular attention to the support for process pools and queues. Briefly the multiprocessing module is modeled after the threading module, it usually nearly identical APIs but scales out using sub-processes rather than threads. The Queue() classes (again, nearly identical interfaces for inter-thread and inter-process) provides for coherent communications from one or many producers to one or many consumers. Used wisely these queues can be used as the primary synchronization as well as communications mechanism among threads or processes. Most locking issues (and race opportunities) are simply and transparently avoided.

For example earlier today I wrote a little utility to spawn a pool of processes (20 by default), a jobqueue and a resultsqueue. Each of the subprocesses ran a daemon-like loop to pull functions and arguments out of the jobqueue and feed the results back through the resultsqueue. From there it's a simple matter to feed function calls our, read results back in (some of which are then fed back through as arguments to a new function call) and so on.

That took about 10 minutes and about 25 lines of code. (The details of the functions and data I was processing are somewhat more complicated and proprietary; but the point is that this silly thing can be used for any Python functions or objects with any arguments. I didn't need to worry about object or data serialization, buffering nor any of that. The Queue() objects handle all that for me. (Since functions are first-class objects in Python I can feed a reference to a function through a Queue just as easily as any other data (objects).

(This particular task was more compute than I/O bound which is why Python's multiprocessing is preferred over threading. Many have said evil things about the GIL --- Python's infamous global interpreter lock --- but even more complaints have been heard about Perl's support for multi-threading).

-3

Perl is quirky and archaic; Python is a much cleaner, more modern language.