473,394 Members | 1,971 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,394 software developers and data experts.

Perl user input scripts

1
Hi all. I am currently working on the below but having real difficulties. Could someone give me some advice or some tips. I keep getting syntax errors each time it is run and the loop is not reiterating properly. (I am using Perl 5.8.2 build 808 MSI version).

Thanks

Reyez


Expand|Select|Wrap|Line Numbers
  1. #!!c:\perl\bin\perl.exe
  2.  
  3. print ("Please enter a four digit customer id:\n");
  4. chomp ($customer_id = <>);
  5.  
  6. while $customer_id =~ /^[0-9]{4}$/);
  7. {
  8.  print("Your customer_id is $customer_id\n");
  9. }
  10.  
  11. else
  12. {
  13.   print ("That is an invalid customer id.  Please try again\n");
  14.   print ("Please enter a four digit customer id:\n");
  15.   $customer_id = <>;
  16. }
  17.  
  18. print ("Please enter a title:\n");
  19. chomp ($title = <>);
  20.  
  21. while $title =~ /^[A-Z] [a-z] {1,3}$/);
  22. {
  23.  print("That is a valid title\n");
  24. }
  25.  
  26. else
  27. {
  28.   print ("That is an invalid title.  You can only have Sir, Lord, Lady, Mr, Mrs, Miss or Ms. Please try again\n");
  29.   $title = <>;
  30. }
  31.  
  32. print ("Please enter a surname:\n");
  33. chomp ($surname = <>);
  34.  
  35. while $surname =~ /^[A-Z] [a-z] {1-19}$/)
  36. {
  37.  print("That is a valid surname\n");
  38. }
  39.  
  40. else
  41. {
  42.   print ("That is an invalid surname.  Please try again\n");
  43.   $surname = <>;
  44. }
  45.  
Jun 13 '07 #1
2 1776
miller
1,089 Expert 1GB
Greetings Reyez,

I suggest that you read the basics of perl programming. Your syntax is completely wonked.

http://www.perl.org/books/beginning-perl/

When you are ready, here is one way to get input like you were attempting to do:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. my $customer_id = '';
  4.  
  5. for (;;) {
  6.     print "Please enter a four digit customer id:\n";
  7.     chomp($customer_id = <>);
  8.     last if $customer_id =~ /^\d{4}$/;
  9.     print "That is an invalid customer id. Please try again\n";
  10. }
  11.  
  12. print "ID is '$customer_id'\n";
  13.  
- Miller
Jun 13 '07 #2
KevinADC
4,059 Expert 2GB
That perl course has really bad matrial or really bad instructors, or both.
Jun 14 '07 #3

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

Similar topics

42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
6
by: von | last post by:
Is it possible to run a Perl script from within a javascript? I have an existing javascript that provides some data - and I want to write that data to a text file on my server via a Perl script...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
4
by: Patricia Mindanao | last post by:
I want to call cgi perl scripts on my web hosters server from my HTML web pages (on the the web hosters server too). It occurs sometimes (especially during development phase) that these cgi-perl...
5
by: walterbyrd | last post by:
I honestly don't know. But, I have seen articles and posts about how PHP is terribly insecure. I don't usually see comparisons to other common web languages. I think the big vulnerablity is...
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
5
by: oaktown | last post by:
Running two input forms on the same page, one php and the other (the one I would like to create) to be written in perl. The idea is to accept an input from a perl script, then pass that input to two...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
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...

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.