Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Perl is still what I reach for when I have a regex heavy task. At my job there's a near 50/50 split between python and perl scripts. I've re-written some of the perl used for general sysadmin tasks in python too, but I haven't seen enough benefit to justify doing more. It works. Plus, in my opinion, perl is more fun to write.


> Perl is still what I reach for when I have a regex heavy task.

That's the point of PCRE though - you get Perl's excellent regex implementation in more places.


It's not usually that there are features I need which python doesn't support, it's just much more cumbersome to use in python compared to perl where it's part of the language and can be used just about anywhere without even adding another import.


The friction difference between "part of the syntax of the language" and "have to use this library" is enormous.


Enormous like "import re"? It is still part of core python.


With perl you just run $foo =~ /regex/ anywhere, you can also put that into an if condition or assign the results to a variable, you can use variables like $1 and $2 (the captures) immediately after, as they are global. You can use any choice of delimiter for the regex to improve readability (i.e. you don't have to use quotes, if your regex contains a lot of quotes).

So you can do while ($foo =~ /bar/) or even ($result) = $foo =~ /bar/.

Python has only raw strings and until recently you couldn't even do if ($regex) { ... } you had to assign the match to a variable and check it, causing lots of nested if/then blocks. It's just clunkier.


Yes.

When writing a Perl script, there's literally zero friction to using regular expressions because they're baked in. I just type what I want to run.

When writing a Python script, I realize I want a regular expression, and I have to stop the code I'm writing, jump to the top of the file, import re, go back to where I was.

Now, maybe I'm writing a quick script and I don't care about tidiness, and I only have to stop what I'm doing, put "import re", and then write the code I want, but still, I'm stopping.

Or I'll wait until I've written the code I want, and go back and put it in. If I remember. If not, I'll find out when I run it that I forgot it.

Or my IDE will show me in red ugly squigglies that I need to right click or hover, and there'll be a recommended solution to import it.

This is all friction that isn't there with Perl.


> stop the code I'm writing, jump to the top of the file, import re, go back to where I was.

If you're just shitting out a one off script and that's really a problem for you, you can just "import re" where you are, there's nothing other than convention and scope that forces you to import everything at the top. Given thats also a problem with sys and os, importing all the commonly used libraries and carrying that around as a template (from print import pprint, anyone?) also seems reasonable, if that's really a problem for you.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: