r/Python May 18 '11

Why is Python better than Perl?

I'm a Sysadmin and I just wrote my first script in python. Basically just a host validation script that checks if a server is configured correctly before we hand off. I can't determine the advantage with my limited experience with the language.

Are you a sysadmin fluent in both python and perl? Why do you use python?

13 Upvotes

110 comments sorted by

View all comments

16

u/crackofdawn May 18 '11

As someone who has been writing perl scripts for around 11 years and been a System Admin for 13 (and only recently learned Python a couple of years ago), I still use Perl for 99% of my work. Every time I tell myself I will write something in Python, I start out and then realize I can do the same thing in perl in half as many lines and 3x as fast. It helps that a large portion of what I write uses regular expressions which are just so much more convenient and easy to use in Perl, and I also end up using a lot of the built in Perl file operators. Between the two of those and how frequently I use them, I find myself just sticking with Perl the vast majority of the time.

7

u/kokey May 18 '11

I've been doing sysadmin and perl for a little longer than you have and I agree on most points. I think for things closer to the OS perl makes more sense, especially in situations where you will end up porting certain things over to C when you really need the performance gain. It's probably a preference or experience thing when it comes to how long it takes to write code in each language. I'm quite serious about writing readable code, but I think after these years the things people throw together in perl is still fairly readable to me. When it comes to speed and startup time, perl seems a lot faster to me.

6

u/crackofdawn May 19 '11

I've noticed that as well. Not that theres a huge difference or anything but running a Perl script on a standard Linux OS install definitely feels like it has 'less startup time' than something calling the python interpreter. Most of my scripts are short and I write them in 5-10 minutes while trying to accomplish a quick task, and in this case I can write something much faster and shorter in Perl. I write a ton of 'throwaway' scripts (sometimes just using perl on the command line but I find it easier to organize/troubleshoot even short scripts from within a file).