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?
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 [1], DBIx::Class [2], DateTime [3], 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.
[1] http://search.cpan.org/dist/Moose/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 [1]) which is more or less the same thing. All ya gotta do is "easy_install packagename" to download, build, and install from it.
[1] http://pypi.python.org/pypiThere 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.
very verbose language
. check CodeGolf tag here and see how compact python can be. Btw, as Bruce Eckel said (quoting from memory), Python is executable pseudocode. Perl is executable line noise - Nas Banov
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.
What are you gonna put your trust in?
(Disclaimer: I have nothing against neither. Just seemed a catchy line.)
I've tried Perl, Python, and Ruby. (I've taken a look at Neko [1], 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 [2] takes place of rigid rules about the best way to code. And where as Perl presented a daunting variety of OO paradigms, Moose [3] is informally becoming the way to do OO.
[1] http://nekovm.org/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.
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:
I must admit that Perl has a few advantages, too. Here are some of them:
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.
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?
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.)
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.
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
[1], 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.
[1] http://perlmonks.orgOn 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.
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.
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.
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:
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.
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.
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.
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.
Reach for Perl under these conditions:
Reach for Python under these conditions:
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.
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.
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 [1]
[1] http://www.odinjobs.com/blogs/careers/entry/perl_php_python_and_rubyI 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.
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).
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 [1] 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.
[1] http://codetojoy.blogspot.com/2007/09/porsches-and-ferraris.htmlThere'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.
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.
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.
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.
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.
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.
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.
I would choose Perl over Python. I'am doing both. Done several big projects in Perl any in Python.
I must say that Perl is the more powerful language. Further, it has through the mighty CPAN libraries for just everything you could imagine. There is nothing what couldn't be done in Perl.
But then, Perl is more complex than Python. Symboltable for example needs a lot of understanding. If you know it you can develop just anything. Like the Moose Framework which is even more complete and functional than Python's OO System.
I like Python for its Syntax. It's a really good readable, but also uses more code than Perl. I like Python also for its big native library. It's also easier to learn than Perl.
If you need powerful language which is really efficient but also hard to learn than use Perl.
If you need language with really nice syntax and language which is mostly done in one good way then choose Python.
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.
Perl has a large number of modules available in CPAN for almost anything. But if you are not following Perl best coding practices (http://oreilly.com/catalog/9780596001735 Damian Conway) as your bible of how to write a Perl code,things can get a bit dicey for you above 100 lines of code in Perl. While Python inherently makes it user to write beautiful code. One reason for this could be the ideology (There's only one way to do it).Thus python code is easier to maintain than Perl. In terms of performance Procedural Perl program will perform better than Python programs, the same cannot be said about object oriented Perl. Every Language has its own advantage over the other if you are going for data munging or file parsing you will find it easier with Perl as nothing beats Perl Regular expressions,while in graphics department Python is way ahead of Perl with good graphics libraries and numerous GUI frameworks like Wxpython(http://www.wxpython.org/) and PyQt(http://www.riverbankcomputing.com/static/Docs/PyQt3/PyQt.html)
Lastly IMHO Python has a steeper learning curve than Perl
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
[1]. The widespread adoption of
setuptools
[2] and easy_install
as the package-management tools of choice, along with environment/dependency tools like
virtual-env
[3] and
zc.buildout
[4], 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.
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 [1] 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.
[1] http://www.stackless.com/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
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.
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.
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.
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.
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).