Python or Perl? + Questions
6 28 Aug 2015 16:18 by u/Dehpuh
Should I learn Python, Perl or both?
- Do they have UNIX terminal compilers like g++ for c++?
- I know Python source code can be run as a script, can Perl?
- I hate forced indenting. can it be avoided with semicolons, brackets et alii?
25 comments
6 u/Drenki 28 Aug 2015 17:21
Perl is a more interesting language than Python or Ruby; the other two are far more fashionable, though. You may want to learn both, but use Python or Ruby in day-to-day projects.
The reason I say it's more interesting is because it was created by someone who studied linguistics. Read this speech given in 1999 (it's still relevant even today) and if it interests you, go read the Perl llama book ("Learning Perl") and see how you like it. I guarantee it's unlike any book about programming you've ever read.
To answer your other questions:
Perl has a repository of libraries called CPAN. It's huge and a bit of a mess trying to find which library is right for you. Don't worry about that too much because it isn't necessary if you just want to try it out.
PHP is a good alternative if you are looking to build resume skills. Even though there are other, more fashionable, languages out there, the large majority is for PHP (just don't expect to end up at a fancy silicon valley start-up with PHP).
4 u/yamalight 28 Aug 2015 16:41
If you are just starting, I'd say python will be a better choice. It's simpler and there's a ton of existing things for it (libraries, courses, tutorials, etc). Perl is a good language too and I'd seen people do magic with it. But it's definitely not easy to learn. And, since it allows for pretty crazy things syntax-wise, if the code is poorly written - it can be very hard to read it.
If you are not into forced indenting, I'd recommend looking at javascript/node.js and ES6/babel. It's a bit more complex than python due to some not-so-nice legacy things, but it is a very powerful tool. If you are interested, I can recommend a couple of places to start learning it.
2 u/thor12022 28 Aug 2015 17:11
I have and do use both perl and Python on a fairly regular basis.
Both languages have their places. But, as much as I love perl, I tend to relegate it to tasks revolving around text manipulation due to it's built in Regular Expressions operators. Python seems to just work better for larger projects, and is (usually) easier to understand. Perl has a tendency to encourage efficiency at the cost of readability.
That said, you asked, which should you learn, not, which should I use. That may be a very different answer, depending upon your reasons. If you love just learning things to see how they work and you have a habit of constantly refactoring for simplicity, learn perl. If you want to learn a language to make yourself more marketable, Python is probably a better choice (although you may want to look into something completely different depending upon your intended field).
2 u/unixfreak 28 Aug 2015 17:11
Personally i prefer Perl. It was my first language learned when coming to linux/bsd and i use it for automating most things still. I find it the easiest to read when it comes to other peoples code. If you know a bit of PHP (or want to), i'd say to go ahead and learn Perl. The syntax is very similar to PHP in common functions and can be useful to learn just for that.
1 u/Craftkorb 28 Aug 2015 17:12
Perl is .. a completely weird language. I wouldn't recommend learning it as first language as it has many things in it that are weird at best. If you want to learn a modern scripting language, and don't want to have forced indention, try ruby.
1 u/pminten 28 Aug 2015 20:10
Neither really has compilers in the gcc sense since both languages are interpreted.
Both Perl and Python can be run as scripts. I would actually expect there to be relatively more Perl scripts than Python scripts since it's well suited for certain scripting tasks (sed/awk-ish stuff in particular is one of its major strengths).
In Python you can't avoid the indentation sensitivity, it's part of the core syntax of the language. Trying to avoid it with semicolons will just result in code that's hard for everyone else to read and that style checkers will complain endlessly about.
As for your main question, I would recommend learning both since they have different things to offer. Learning Python will teach you about writing clean and correct programs in an interpreted language (which has less "compile time" checks than C/C++). Learning Perl on the other hand will allow you to write quick text editing scripts for when you just need to get a job done.
Ruby, as suggested on this thread, is a bit of a mix of Perl and Python. It doesn't have the Python culture of cleanless but it doesn't have forced indenting. It's not as hard to read as Perl but it's less efficient in text manipulation. It does have extensive libraries like the other two so it's definitely a practical choice.
Oh, and I suggest not starting with PHP. PHP is better faced when knowing other languages so you already know which "features" make sense and which to avoid.
1 u/effusive_ermine 29 Aug 2015 01:58
If those are the only choices: Python. If you're willing to consider other options, Ruby
0 u/svipbo 30 Aug 2015 17:04
I've spent quite a lot of time using Perl, and I'm not really a fan. The culture around Perl is degenerate, constantly trying to prove their relevance. They try to excuse the bad choices for Perl's syntax by saying that its inventor was a "linguist", as if we should trust some alleged academic authority instead of our own eyes and brains.
I agree with most of Xah Lee's rants about the Perl community, e.g. http://xahlee.info/UnixResource_dir/perlr.html
I haven't used Python much, but I'd recommend Python instead, just to help Perl die.
However, Python is said to have a degenerate culture as well: see http://xahlee.info/perl-python/python_doc.html and http://xahlee.info/perl-python/xlali_skami_cukta.html.
1 u/Dehpuh [OP] 01 Sep 2015 18:33
Every culture is degenerate if you look hard enough
0 u/TrevorLahey 01 Sep 2015 17:34
Perl works great for many, many tasks. Older .NE. bad, Newer .NE. Inherently Better. Learn both, use whichever seems to be the best fit for a given task.
0 u/idunnome 07 Sep 2015 16:47
My personal opinion: learn both eventually.
More immediately, focus on one of the two, because there are a lot of syntactical differences that might be confusing. Which of the two you go with first would depend largely on what you want to accomplish and what your environment is using most of the time.
At my last job (a SysAdmin), we did almost everything in Perl, and it was Good. At my current job (not exactly SysAdmin, but close), I haven't used Perl at all. I'm more likely to use bash, and lately I've seen reason to delve into Python.
As others have mentioned, there's a lot of stuff out there already written in Python. Although you may not like the forced indentation (it's not a favorite of mine either), it does help to make the code easier to follow when looking at someone else's code. Looking at someone else's Perl code, in comparison, can be an exercise in futility.
As with almost any other language of importance in the unix realm, adding "#!/usr/bin/env LANGUAGE" (where "LANGUAGE" is your language of choice) as the first line of your script will do the job nicely once you've set the execution bit for the file, whether you're looking at Python, Perl, or (as some have suggested) Ruby.
For the work around for forced indenting, if you're looking at portability, you're better off just dealing with the formatting the way it is. You'll be glad you did.
Hope this helps.