Perl has exception handling, its only that its not available via your usual try-catch syntax. If you want a more sugary exception handling syntax there is always Try::Tiny ( http://search.cpan.org/~doy/Try-Tiny-0.09/lib/Try/Tiny.pm).
Another advantage Perl has over Python in case of parsing is that regular expressions are first class elements in Perl, so they can be passed around like objects. Combine them with more powerful things like given-when(http://perldoc.perl.org/perlsyn.html#Switch-statements) and parsing becomes a lot more easier when compared to Python. Smart matching is a great feature. And all this obviously leads to better performance in terms of speed because less code to process means (to an extent faster code). And syntactically as well.
Imagine doing such a thing in Python. There isn't smart match operator at the first place, there is no switch statement, and on top of that dealing with innumerable regular expression functions(compile,match,search) with try-catch statements inside if-else loops. This piece of code in Python won't be easy to read and solution isn't elegant and better than Perl either.
Perl turns out to be better in all ways, the code is readable, concise, faster and powerful.
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."
Perl'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#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.p...
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.
If 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?
Perl'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.
Another advantage Perl has over Python in case of parsing is that regular expressions are first class elements in Perl, so they can be passed around like objects. Combine them with more powerful things like given-when(http://perldoc.perl.org/perlsyn.html#Switch-statements) and parsing becomes a lot more easier when compared to Python. Smart matching is a great feature. And all this obviously leads to better performance in terms of speed because less code to process means (to an extent faster code). And syntactically as well.
Imagine doing such a thing in Python. There isn't smart match operator at the first place, there is no switch statement, and on top of that dealing with innumerable regular expression functions(compile,match,search) with try-catch statements inside if-else loops. This piece of code in Python won't be easy to read and solution isn't elegant and better than Perl either.
Perl turns out to be better in all ways, the code is readable, concise, faster and powerful.