in reply to Reverse a Word - without reverse??
use strict; my $string1 = "abcba"; my $string2 = "abc1da"; if (&reverser($string1)){ print "Matched! Strings are palindromes.\n"; } else{ print "Sorry, the strings are not palindromes.\n"; } if (&reverser($string2)){ print "Matched! Strings are palindromes.\n"; } else{ print "Sorry, the strings are not palindromes.\n"; } sub reverser{ my $temp = shift; my ($reverse, @temp, @temp2); @temp = split ('',$temp); foreach (@temp){ unshift(@temp2, $_); } $reverse = join('', @temp2); $temp eq $reverse?1:0; }
Should do what you're requiring without using the regex. You're just running the array you've made from your string and reversing it using the unshift.
There is no emoticon for what I'm feeling now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Reverse a Word - without reverse??
by PetaMem (Priest) on Mar 07, 2004 at 21:42 UTC |