473,686 Members | 3,347 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

palindrome program

24 New Member
hi,iam learning perl for the past two weeks and i was told to do a palindrome program.can any one help me with the code please.
Aug 28 '07 #1
16 17386
4,059 Recognized Expert Specialist
Help? Yes. Do it for you? No. Post the code you have written so far.
Aug 28 '07 #2
24 New Member
Expand|Select|Wrap|Line Numbers
  1. do {
  2.     print "Type a word or phrase: ";
  3.     $line = <>;
  4.     @letters = split //, $line;
  5.     $reverse = join "", reverse @letters;
  7.     if (@letters == 1) {
  8.         print "One letter palindrome, trivial!\n";
  9.     }
  10.     elsif ($reverse eq $line) {
  11.         print "This is a palindrome.\n";
  12.     }
  13.     else {
  14.         print "Not a palindrome.\n";
  15.     }
  16. } while ($line);
this is the code i have done so far.the problem is every word i type,it shows it is palindrome.
Aug 30 '07 #3
1,089 Recognized Expert Top Contributor
Don't forget to chomp the $line variable to remove the return character.

Also, reverse on a scalar does a string reversal. So the split and join operation is extra work.

Expand|Select|Wrap|Line Numbers
  1. chomp($line);
- Miller
Aug 30 '07 #4
4,059 Recognized Expert Specialist
Also, reverse on a scalar does a string reversal. So the split and join operation is extra work.
using split and join might be a requirement for the assignment. Someone posted the exact same assignment on another forum a couple of days ago. But the code on the other forum wasn't even close to getting it right.
Aug 30 '07 #5
3,509 Recognized Expert Moderator Specialist
here is the program .see whether it works out

While I know you think you are being helpful, simply providing the full script to the user, you are actually hindering their learning process. It is the policy of thescripts.com forum NOT to provide the answers to people's school work. Instead, we request that they post the code they are working on and help them to get it correct for what they are trying to do.

In the future, please work with the users code and refrain from the urge to just post the code they need.


Aug 30 '07 #6
24 New Member
tank you for the code,but the problem is, in the o/p after enetring the string nothing shows.that is the result is not known whether the enetred string is palindrome or not.
Aug 30 '07 #7
24 New Member
thank you guys for the support,ive solved the problem.here is the code for palindorme.

Expand|Select|Wrap|Line Numbers
  1. #!/user/bin/perl
  2. $a=<STDIN>;
  3. chomp($a);
  5. @aa=split("",$a);
  6. print "@aa\n";
  8. @b=reverse (@aa);
  9. print "@b\n";
  11. $c=join("",@aa);
  12. $d=join("",@b);
  14. if ($c eq $d) {
  15.     print "the given string is palindrome\n";
  16. } else {
  17.     print "not a palindrome\n";
  18. }
Aug 30 '07 #8
3,509 Recognized Expert Moderator Specialist
thank you guys for the support,ive solved the problem.here is the code for palindorme.
Good job! Thank you for posting your working solution and letting us know you solved your issue!


Aug 30 '07 #9
4,059 Recognized Expert Specialist
here is the program .see whether it works out

All that for a simple palindrome script? Well, it does adhere to the TIMTOWTDI philosophy of perl coding.
Aug 30 '07 #10

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

Similar topics

by: Runic911 | last post by:
Does anyone know how i can fix my Palindrome program? s = raw_input('Enter a String: ') punctuation = '%$!*.,-:? ;()\'\"\\' i = 0 h = 0 t = 0 p = '' z = 0 while s!= ' ':
by: Lorin Leone | last post by:
Can anyone help me modify the program so that it recognizes strings like "Anna" as palindromes. To make the program "case-insensitive." using the built-in C++ function "toupper". and so that it recognizes strings like "race car" as palindromes, have the program ignore spaces in the input string. Here is my code:
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: The input is the string whose largest palindrome substring should be
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 return It's a Palindrome! and if I enter 33636 or 11214, it returns It's not a Palindrome!
by: 1051109210 | last post by:
class MyStack{ public: MyStack(int sz=10); ~MyStack(); char pop(); void push(char ch); bool isEmpty(); bool isFull(); private: char *value;
by: bigtd08 | last post by:
help writing this palindrome program for my c++ class. HERE WHAT THE CODE SHOULD BE LIKE. Write a program that takes a line of input from the keyboard and check to see if that line is a palindrome. Your program should ignore blanks, punctuation, and lettercase Your program should output what the user entered as well as the reversed line. Sample output: Please enter a phrase, and I will tell you if it is a palindrome. >> Madam I'm Adam
by: Kreators | last post by:
Hi everyone i'm newbie here in bytes and a newbie in programing i need your help! can you correct my program when my program compile its say Process completed. but when i put a Word and Run my program does not show an output what is the problem? import javax.swing.*; public class Palindrome { public static void main(String args) { String A; int i,palindrome=1;
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.