I am fairly familiar with python, from a system automation and tool building prospective; I am a sysadm by trade. I recently started a new job at a company that wants to standardise on perl, for which I know none. So I need to get up to speed on perl pretty quickly and was hoping someone could point to some helpful reference aimed at python developers/scripters trying to learn the basics of perl. I found this about going from perl to python; I need the opposite. I bought the llama book, but haven't yet been able to start reading it. Any input / suggestions?
-
8You aren't going to learn Perl by buying a book and not reading it. Read it. It won't take you any time if you already know Python. You'll probably want to change jobs once you have finished reading it though! – David Heffernan Mar 28 '11 at 14:31
-
1The reason i learned Python in the first place was because Perl seemed needlessly complicated for the little bit of automation/scripting i needed. You guys are just confirming my fears! bummer :p – tMC Mar 28 '11 at 14:37
-
1Well...I would say Perl is probably easier to use for the shorter and simpler scripts. It gets hairier for longer and more complex programs. What really bugged me, going in the opposite direction, was the similarity - I kept writing Perl syntax in my Python programs, then vice-versa. So I decided I should dump one, and it was clear that I liked Python a lot better. – Tom Zych Mar 28 '11 at 14:42
-
Read the book and then come back. We must not teach you basic stuff that you can teach yourself by reading yourself....this is not the i-am-lazy support. – Mar 28 '11 at 14:43
-
2Don't worry too much, perl is pretty popular in my company and newcomers generally pick it up pretty quickly. For short automation and scripts I've seen people making useful scripts since first day with perl. – bvr Mar 28 '11 at 14:44
-
3FYI: Perl is the name of the language; `perl` is the name of the program that runs the Perl scripts. If you don't use them properly, I won't be the only one telling you the difference. :) – shawnhcorey Mar 28 '11 at 15:22
-
3I don't envy anyone at a workplace that would move *to* Perl in 2011. – Glenn Maynard Mar 28 '11 at 16:40
-
3@Tom - Granted, Perl is very forgiving of hairy code, but it doesn't *force* you to write that way. It runs well-structured and clear code just as well or better. A little self-discipline goes a long way. – Sherm Pendley Mar 28 '11 at 17:12
-
4wow, people are really trying to be helpful today... – ysth Mar 28 '11 at 17:29
-
1@ysth - Well, *some* people are. Others... not so much. :-( – Sherm Pendley Mar 28 '11 at 17:56
5 Answers
Crank through the Llama (it will be easy) and when you're done with that check out Effective Perl Programming and/or Modern Perl. They'll help you avoid the mistakes encouraged by all the crappy tutorials written in 1994 that still seem to reverberate around the net.
Take the time to check out Moose and in particular MooseX::Getopt
BTW, I like Perl more than Python, but I don't feel the need to run Python down every time it is mentioned. WTF Pythonistas? Please consider for a moment that no language is perfect, and no language holds the "ultimate truth of programming". As Brooks pointed out, there is no silver bullet. Python has some things that are great, Perl has some things that are great. Python has some things that are crap, Perl has some things that are crap.

- 26,689
- 7
- 59
- 100
-
7+1 for that last paragraph. Everyone has preferences, and there's no need to be a jerk about it. – Sherm Pendley Mar 28 '11 at 17:13
-
3+1 for all the answer. Modern Perl is a really wonderful tour through Perl. I’d probably not recommend Moose for sysadminy things… though there is also [Moo](http://search.cpan.org/perldoc?Moo), which might make command line versions zippy and nearly as powerful code-wise; easy to switch later too. WRT your BTW: [Perl and Python hackers compared](http://sedition.com/img/p/p/h/perl-and-python-hackers.png). – Ashley Mar 29 '11 at 00:45
-
@Ashely, Moose can be a bit slow at startup, but over the past few years it has gotten much, much better. I advocate Moose and MooseX::Getopt (and the related config file modules) for scripting anything more than a tiny one-off because they make so much of the drudgery of these tasks disappear. Declare your script/app object, parse your config file and override that with CLI parameters all in a few lines of declarative code. Use `BEGIN { package Foo; ... }` blocks to make related objects live in a single file, and you can build a powerful, flexible script very quickly. – daotoad Mar 29 '11 at 14:33
I know you already have a book, but from your description I would have recommended Automating System Administration with Perl

- 68,119
- 3
- 51
- 97
Some translations of typical python idioms into perl:
- List comprehension
[x * x for x in range(10)]
becomesmap {$_ * $_} 0..9
- Filter
filter(x > 5, range(10))
becomesgrep {$_ > 5} 0..9
- A function
def f(x, y): return x + y
becomessub f { my ($x, $y) = @_; $x + $y }
As a quick reference for built-in functions, I find perldoc -f <function_name>
very useful.
Finally, be aware that while single (''
) and double-quoted (""
) strings are identical in python, they are not in perl! For example, "$a\n"
will be interpolated, i.e., '$a' will be replaced by the value of variable $a.

- 1,807
- 2
- 21
- 35
I went from Python to Perl as well for work. I used Learning Perl as well and it helped me learn Perl fairly well within a weekend's worth of hacking around.
The best way to learn Perl is to read that textbook and use it. You could rewrite your existing Python projects in Perl to speed up learning the language if you're looking for exercises.

- 103
- 8
Your best bet it just to work through the Llama book and do the exercises. And coming from Python, which has somewhat similar syntax, make sure you're writing Perl instead of Python.

- 13,329
- 9
- 36
- 53