in reply to Re: Palindrome Program without Reverse function
in thread Palindrome Program without Reverse function
#!/usr/bin/perl use strict; use warnings; chomp(my $name = <>); my @arr = split //, $name; my $is_palindrome = 1; for my $i (0 .. $#arr / 2) { # warn "$arr[$i] eq $arr[ -$i - 1 ]"; if ($arr[$i] ne $arr[ -$i - 1 ]) { undef $is_palindrome; last } } print 'Word is', $is_palindrome ? q() : ' not', " a palindrome!!!\n";
|
|---|