Log in

View Full Version : Help!! learner in Perl



kazzaH
06-07-2006, 10:58 AM
hello, im a learner in PERL and have to create a perl program.
when run the user is prompted for a 4 digit cust ref no, then
title, surname, forename, sex, DOB, vision measurement.
all these nee to be verified, if any fails an error message has to appear, then prompted to re-enter info. the verification is
cust no - 4 digitd
title - 1-4 alpha charc, and allow titles, Dr, Lady, Lord, Miss, Mr, Mrs, Ms, Sir
Surname - 1-20 alpha charc
Forename - 1-20 alpha charc
Sex - 1 charc, either m or f ( upper or lower)
DOB - in dd/mm/yyyy
vision - 1-2 digits ( between 1-99

i have created some code for this but keep getting errors, don't know why?? Could anyone please tell me what ive got wrong in this code?

print ("Please enter your customer ref number:\n");
$Custref = <STDIN>;
chomp ($Custref);
while ($Custref !~m/^[0-9]{4}$/)
{
print ("Sorry Please try again:\n");
$Custref = <STDIN>;
chomp ($Custref);
}

!!!!!while bits (instead of writing it all out!!!!!

Title while ($Title !~m/^[Dr|Lady|Lord|Miss|Mr|Mrs|Ms|Sir]{0-4}$/)
Surname while ($Sur !~m/^[a-zA-Z]{0-20}$/)
Forename while ($Fore !~m/^[a-zA-Z]{0-20}$/)
Sex while ($Sex !~m/^[m-M|f-F]{1}$/)
DOB while ($Dob !~m/^[0-9999] not sure how to make it valid for
DD/MM/YYYY
Vision while ($Vision !~m/^[1-99]{1-2}$/)

I just keep going round in circles, so any help will be much appreciated

karen:eek:

Twey
06-07-2006, 11:06 AM
Well why don't you give us the errors? :)

kazzaH
06-07-2006, 04:58 PM
sorry

when i run just the " enter ref number with the while bit
it comes up with:

syntax error at cust.pl line7, near ");"
execution of cust.pl aborted due to compilation errors.

this should work as far i can see!!!!:eek:

Twey
06-07-2006, 05:14 PM
Which line is 7?
Paste your whole script here. In [code] tags, please.

kazzaH
06-08-2006, 03:47 PM
hiya

got some of the code working, (finaly)
i can't seem to copy my script from perl into anything for some reason!!!
why is this???

Does anyone actually still use perl as ive asked in the web dept at work an they say they've never used it!!!!

the only problem ive got now is how to verify the date so it only accepts
DD/MM/YYYY not sure how to get it to include the backslashes!!!

does anyone know a good place to get info on perl as ive had a look but a lot of it doesnt go into much detail.

much appreciated:) :) :) :)

Twey
06-08-2006, 05:46 PM
Does anyone actually still use perl as ive asked in the web dept at work an they say they've never used it!!!!I'd say that they were inexperienced and incompetent, then. I've probably just offended half of them, but I don't really care :) Perl is still used commonly in many roles, of which CGI is one. In fact, it's probably the most popular CGI language out there, if we ignore PHP which can be run as a CGI parser to work around webserver or permissions problems.
does anyone know a good place to get info on perl as ive had a look but a lot of it doesnt go into much detail.The perldoc (http://www.die.net/doc/linux/man/man1/perldoc.1.html)(1) utility and the standard files for it that come with Perl are an excellent reference.