Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: palindrome using regular expressionsby Hofmator (Curate) |
on Oct 10, 2006 at 11:28 UTC ( [id://577377]=note: print w/replies, xml ) | Need Help?? |
This uses the recursive definition of a palindrome:
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
|
|