3 ms·
Yeah, it's through eval() which is a questionable design decision at best. Regular expressions can be passed as objects in Python, too. Three functions is hardl
by jergosh 15y ago
Yeah, it's through eval() which is a questionable design decision at best. Regular expressions can be passed as objects in Python, too. Three functions is hardly 'innumerable'.
"Perl turns out to be better in all ways, the code is readable, concise, faster and powerful."
To each his own, I guess.
- kamaal 15y agoI 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 15y 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 15y 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.
- chromatic 15y ago[Perl 5 exception handling works] through eval() which is a questionable design decision at best. eval() and eval {} are very different constructs in Perl 5. The questionable design decision there is reusing the keyword.
- tene 15y agoPerl's block eval is not string eval. Quoting from 'perldoc -f eval': In the second form, the code within the BLOCK is parsed only once--at the same time the code surrounding the "eval" itself was parsed--and executed within the context of the current Perl program. This form is typically used to trap exceptions more efficiently than the first (see below), while also providing the benefit of checking the code within BLOCK at compile time. The only (significant) questionable decision there is the name; its functionality is the same as 'try' in other languages. There are some issues, however, with properly dealing with failures in an eval block. They're fairly obscure, and won't often come up, but they're explained in the "Background" section of the Try::Tiny docs: http://search.cpan.org/~doy/Try-Tiny-0.09/lib/Try/Tiny.pm#BACKGROUND http://search.cpan.org/~doy/Try-Tiny-0.09/lib/Try/Tiny.pm#BA... Try::Tiny is a minimal module with no dependencies that does the least amount necessary to get 'try' and 'catch' keywords into the language, connecting handler blocks to guarded blocks. There are some problems with this, like trying to use loop control or return statements inside of a catch block. The normal way to get good error handling that deals with all of the potential issues without introducing others is TryCatch, which also adds extra features, like Moose type constraints on multiple catch blocks: http://search.cpan.org/~ash/TryCatch-1.003000/lib/TryCatch.pm http://search.cpan.org/~ash/TryCatch-1.003000/lib/TryCatch.p...