3 ms·
Running code in the regex with (?{ ... code ... }) is cheating, because you can just put a whole Perl program in there. It's also one of the many badly implemen
by lazyjones 13y ago
Running code in the regex with (?{ ... code ... }) is cheating, because you can just put a whole Perl program in there. It's also one of the many badly implemented features of Perl that could be more useful if the implementation was any good. Using it will cause subtle bugs when you use regexps in the code called from there (even if you just call a sub/function), because the context (of regexp processing) isn't saved.
- kamaal 13y ago>>Running code in the regex with (?{ ... code ... }) is cheating, because you can just put a whole Perl program in there. Would you like to call eval, recursion, macros, closures and many such things cheating? Sorry but doing things without understanding or knowing the true consequences of what you are actually writing, always causes bugs. And that's true with any programming language. Perl has many features which are designed to make the language powerful enough, to express solutions to very complex problems that other wise demands piles and piles of code in other languages. That's the whole point of the Perl language as a whole, you should take a really hard problem on a Friday night which you would find very difficult to code up in a weekend and then go to a finished script by Sunday evening.
- lazyjones 13y ago> Would you like to call eval, recursion, macros, closures and many such things cheating? Yes, in the context of "I did this with just a regexp". > Sorry but doing things without understanding or knowing the true consequences of what you are actually writing, always causes bugs. And that's true with any programming language. That's a cheap excuse for implementing this in a way that is just plain wrong, or too limited to be useful, when it could have been implemented correctly (at least if enough capable programmers still understood Perl's source code to work on it). > Perl has many features which are designed to make the language powerful enough I never disputed that. I used Perl almost exclusively in the past 14 years or so, so I know what I'm talking about. These broken language features are the biggest PITA about the language. They are useful for some very specific tasks, but useless for others where they could be used if they had been implemented correctly. Adding a feature with more gotchas than useful use cases is not the way to making a language more useful and enjoyale.
- viraptor 13y ago> Sorry but doing things without understanding or knowing the true consequences of what you are actually writing, always causes bugs. And that's true with any programming language. I agree with this in general, but not in this situation. Let's say you use a function you verify doesn't contain regex matching. Then someone else changes that function to contain regex - s/he shouldn't need to (and may not be able to) verify every single place where this function is used - introducing a hard to find bug. Who caused a bug here? In my opinion that's the regex engine/language creator who didn't decide to either handle this case correctly in all cases, or explicitly fail in this edge case.