CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Problem on Palindrome: Edit Log



iammgg
Novice

May 25, 2017, 2:59 AM


Views: 2037
Problem on Palindrome

It seems that there's a problem with my code. The instruction is written inside of this code (comment).

Code
#!/usr/bin/perl 
use strict;
use warnings;

=pod
Write a perl program that will check if
an input is a palindrome.
This is not case-sensitive.

Example:
Input a string: Racecar
The word Racecar is a palindrome

Input a string: hello
The word hello is not a palindrome.
=cut

print "Input a string: ";
my $string = <STDIN>;
chomp ($string);

if($string eq reverse $string) {
print "The word $string is a palindrome.\n";
}
else {
print "The word $string is not a palindrome.\n";
}


the output always says (if I input 'Racecar'), "The word Racecar is not a palindrome."

But when I input "hello" it says, "The word hello is a palindrome."

Thanks in advance.


(This post was edited by iammgg on May 25, 2017, 8:42 AM)


Edit Log:
Post edited by iammgg (Novice) on May 25, 2017, 8:42 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives