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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


May 25, 2017, 2:59 AM

Views: 2299
Problem on Palindrome

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

use strict;
use warnings;

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

Input a string: Racecar
The word Racecar is a palindrome

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

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