Syntactic Confectionery Delight | |
PerlMonks |
Re: Regex Homeworkby Zaxo (Archbishop) |
on Feb 24, 2004 at 07:21 UTC ( [id://331344]=note: print w/replies, xml ) | Need Help?? |
The reason this smelled so of homework is that many instructors love these tricky regex puzzles. "Do <whatever> with a single regex" whether or not that is a sane thing to do. Most such problems are better solved with several regexen or other constructs, all pasted together with a bit of logic. Your problems each consist of two distinct logical requirements.
Those subs could easily be autoloaded. The arithmetic tests differ, and their best implementation may or may not involve a regex match. The odd number of ab pairs is easily implemented with a global one, together with bitwise &, The condition for the second problem is better done with tr///, because it is quicker for counting individual characters. However it looks, tr/// is not really a regex solution. The logical or appearing in the condition allows a tidy way to package those conditions. and the solutions, All that localizing of $_ is to allow $_ to be the default argument without causing any modifications to it. After Compline,
In Section
Seekers of Perl Wisdom
|
|