http://www.perlmonks.org?node_id=382593


in reply to Finding longest palindrome from a string

here is my code:
sub palindrome{ my $x=shift; my $prev=0; while ($x=~/(([a-z0-9]+)[a-z0-9]?(??{reverse $2}))/gi) { $max=$1 if (length($1)>$prev); $prev=length $max; } $max }

update:

Sorry monks i haven't read the question carefully, left out space condition itself.

Replies are listed 'Best First'.
Re^2: Finding longest palindrome from a string
by ccn (Vicar) on Aug 13, 2004 at 10:07 UTC

    Your code doesn't work with 'ababbab'