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

When I think "string handling" in a Perl-vs-Python sense, I think "regex syntax". There are 3 distinct tiers: Perl and Ruby's built-in syntax, PHP's preg_* functions, and finally the Python (and perhaps Java?) Extreme OO style. (In descending order by my preference.)

Python's approach also eliminates the pattern of `if (preg_match(...)) { use captured groups; }` since the match object comes back as a return value instead of either a reference or magic variables, and assignment of that value is illegal inside the if's condition. Very Pythonic, but adds an extra line of code to assign the match separately from testing the result.

(Edited a bunch because I fail at non-markdown.)



When working with regular expressions in Perl, the RegularExpressions::ProhibitCaptureWithoutTest perlcritic policy (default severity 3) helps avoid some common mistakes.

http://search.cpan.org/~elliotjs/Perl-Critic-1.115/lib/Perl/...




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: