473,383 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

another palindrome problem

i'm a new perl learner, this is the first perl task i will do. please help me.

The user can input a string, and then a script will check to see if the string is a palindrome or not, displaying the result to the user on another page (include the original string that they input in the displayed output). Disregard the case of letters, as well as spaces and any punctuation symbols in the sentence (use Perl string routines to deal with these issues) when you check to see if it is a palindrome.
For example, the string "Madam, I'm Adam" is a palindrome (disregarding upper/lower case, spaces, and punctuation symbols), and the number 15751 is a palindrome too. The strings "Ma'am, I'm Adam" and "34546" aren't. also allow the user to input up to five strings at once and display results for all of them on the same page. If the user only inputs one or two strings to test, then you should only output information about those strings (i.e. don't assume that they will enter exactly five strings).
Dec 8 '07 #1
5 3478
KevinADC
4,059 Expert 2GB
Sorry, but nobody here is going to do your class/course work assignment for you. If you write some code and make an attempt you may get some help.
Dec 8 '07 #2
i'm a new perl learner, this is the first perl task i will do. please help me.

The user can input a string, and then a script will check to see if the string is a palindrome or not, displaying the result to the user on another page (include the original string that they input in the displayed output). Disregard the case of letters, as well as spaces and any punctuation symbols in the sentence (use Perl string routines to deal with these issues) when you check to see if it is a palindrome.
For example, the string "Madam, I'm Adam" is a palindrome (disregarding upper/lower case, spaces, and punctuation symbols), and the number 15751 is a palindrome too. The strings "Ma'am, I'm Adam" and "34546" aren't. also allow the user to input up to five strings at once and display results for all of them on the same page. If the user only inputs one or two strings to test, then you should only output information about those strings (i.e. don't assume that they will enter exactly five strings).




below is my code, i can judge palindrome disregarding upper/lower case, spaces, and punctuation symbols, but i do not know how to judge five string together. please help me.
Expand|Select|Wrap|Line Numbers
  1. do{
  2.  
  3.     # read the input
  4.     print "Type a word or phrase: ";
  5.     $line = <>;
  6.  
  7.     # strip out stuff that would disturb the palindrome comparison
  8.     # and convert to lowercase...
  9.     $line =~ s/\W//g; # removes space and nonalphanumerics        
  10.     $line =~ tr/A-Z/a-z/;  # converts to lowercase. Better: lc($line) !
  11.  
  12.     # get the list of letter and reverse it
  13.     @letters = split //, $line;
  14.     $reverse = join "", reverse @letters;
  15.  
  16.     # a palindrome is equal to its reverse or a one letter word.
  17.     if(@letters == 0){
  18.     print "End of session\n";
  19.     }
  20.     elsif(@letters == 1){
  21.     print "One letter palindrome, trivial!\n";
  22.     }
  23.     elsif($reverse eq $line){
  24.     print "This is a palindrome.\n";
  25.     }
  26.     else{
  27.     print "Not a palindrome.\n";
  28.     }
  29. }while($line);
  30.  
Dec 8 '07 #3
KevinADC
4,059 Expert 2GB
The strings "Ma'am, I'm Adam" and "34546" aren't. also allow the user to input up to five strings at once and display results for all of them on the same page. If the user only inputs one or two strings to test, then you should only output information about those strings (i.e. don't assume that they will enter exactly five strings).
What have you tried in order to accomplish the above requirement of your script?
Dec 8 '07 #4
i have no clue about that yet. can you give me some little hint.i will try it myself. thank you very much.
Dec 9 '07 #5
KevinADC
4,059 Expert 2GB
i have no clue about that yet. can you give me some little hint.i will try it myself. thank you very much.
use the push() function.
Dec 9 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Amar Prakash Tripaithi | last post by:
Dan Hoey, who had recently graduated, wrote a C program to look for and construct the following beauty: A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop, a pint, a catalpa,...
32
by: ramakrishnadeepak | last post by:
HI Everybody, I 've to submit a program on c.Can any one help me plz.........The problem is like this:: Write a program which computes the largest palindrome substring of a string. Input:...
4
by: outofmymind | last post by:
hi, im trying to solve the following question: Create a class responsible for determining whether a string is a palindrome. Show your test cases. Palindome mypal("bob"); ...
3
by: colinNeedsJavaHelp | last post by:
I am still having an exceptional amount of trouble with java. This is my new assignment, if anyone can help I would greatly appreciate it. I don't even know where to start. A word or phrase in...
2
by: Synapse | last post by:
aloha people! I need help in my java palindrome program. It's a 5-digit palindrome checker. The code below is running good but i got a few problems on it. If I enter 33633, 11211, 45554, it will...
2
by: xlilxmizzxinnocentx | last post by:
Hiya I was woundering if anyone could help me. A few weeks ago i started using vb 5.0 and now im trying to make a code to determine if a word is a palindrome or not. The code that i have tried dose...
20
by: Wabz | last post by:
Hello mates, Does anyone know how to write a function that tests if an integer is a palindrome in C language?
4
by: vicestner | last post by:
Write a Java program that prints the longest palindrome in an input file to standard output. A palindrome is a string whose reverse is the same as the original. Ignore case, whitespace, and...
1
by: rbelgane0 | last post by:
writting a program which determine if the text line has palindrome o not> in c++ but I could not do that plzzze thank #include <iostream> #include <string> #include <cctype> using namespace...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.