in reply to palindrome using regular expressions
This uses the recursive definition of a palindrome:
- A single letter is a palindrome.
- Or a palindrome consists of a single letter, an (optional) palindrome and the same single letter.
As for other solutions, there is of course the non-regex way of doing join '',reverse split //, $_ eq $_ but that is probably not what you are looking for.
Note that my $r = "(??{\$palindrome})"; is equivalent to my $r = '(??{$palindrome})';, there is no reference involved (as I thought at first glance).
Update: Minor typo correction
-- Hofmator
Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In Section
Seekers of Perl Wisdom