Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A palindrome is a number or a text phrase that reads the same backwards as it does forwards. For example, each of the following seven-digit
- A palindrome is a number or a text phrase that reads the same backwards as it does forwards. For example, each of the following seven-digit integers is a palindrome: 1234321, 5555555, 4565654 and1126211. Each of the following seven-character strings is a palindrome: abcdcba, deified,racecar, peeweep, rotator.
- Write a program that reads in a seven-character string/number and determines whether or not it is a palindrome. It should print PALINDROME or NOT based on whether or not it is, indeed, a palindrome or not.
- If the input is not 7 characters long, output an error message labeled with ERROR and don't attempt to process the value.
- Write a Perl program, keeping in mind different ways to test string and numeric equality.
- Think about how you can test different types of input, including string/character data and numeric data. For this program, you can't use the reverse function, which over-trivializes the solution.
- We're focusing on practicing with all of the tools available in Perl, so you're being guided to make this solution a bit more complex than it could be. :)
- Remember to have #!/usr/bin/env perl as the very first line of your program to use the appropriate version of Perl on the system (installed with perlbrew).
- Use use Modern::Perl; in your program.
- Output the phrases PALINDROME OR NOT exactly on a separate line from the input.
- Do not use arrays or other libraries for this program.
- Make sure to use the use Modern::Perl in your program.
- You may not use the reverse function, which reduces the solution to the incredibly simple:if($originaleq reverse $original)
{
say"PALINDROME!";
}
Example
Enter in a 7 character phrase: 1111111
PALINDROME
Example
Enter in a 7 character phrase: racecar
PALINDROME
Example
Enter in a 7 character phrase: 1234321
PALINDROME
Example
Enter in a 7 character phrase: 1234522
NOT
Example
Enter in a 7 character phrase: abluent
NOT
Example
Enter in a 7 character phrase: 1234567
NOT
Example
Enter in a 7 character phrase: 123
ERROR: That is not a 7-character input.
Example
Enter in a 7 character phrase: 12345678
ERROR: That is not a 7-character input.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started