2 ms·
I don't think you got my point about regular expressions in Python. If its only one regular expression, then its 3 functions. But if say you have 20 regular exp
by kamaal 16y ago
I don't think you got my point about regular expressions in Python. If its only one regular expression, then its 3 functions. But if say you have 20 regular expressions, now you have 60 function calls. Say you have to add 6 statements of exception handling to each of this, you now have 360 statements. Imagine this inside a giant if-else loop structure.
Without a doubt the Perl solution is a lot more cleaner than Python solution.
- jergosh 16y agoIf you want to match a regexp in Python, you can just say: m = re.match("some_regexp", my_str) You don't need to compile regexps before use but you get better performance if you do when matching the same thing multiple times (no idea if there's a Perl equivalent). Also match() and search() have different semantics and you don't use them at the same time. So it's one statement in Python per match. Also how do you propose to get an equivalent of (non-mandatory) exception handling in Perl code without extra statements?
- ajross 16y agoPerl's regexes are part of the syntax of the language. They're compiled when the script is. That's why the perl syntax is cleaner and the implementation more robust. A bug table of regexes to parse fields out of a record or whatnot looks natural (i.e. declarative) in perl; in python it's kind of a big, imperative mess. Perl exception handling is quirky, but pretty clean. You raise an exception with die() and "try" a block with a simple eval. It's basically the same amount of syntax. The one bit perl lacks as a builtin is the type-based exception matching; you have to do that logic yourself.