1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Perl Course at Home

Discussion in 'Scripting & Programming' started by the1stefan, Dec 17, 2006.

  1. the1stefan

    the1stefan New Member

    3
    0
    1
    wonder if anyone can help me. I am doing a Web Design home study course and I am stuck on the Perl Section. When I was just learning the theory about the Perl Language I was fine but I can not put this knowledge into practice. I have to create a Perl program to acquire customer information, the program must ask for the following: Customer Reference Number (4 Digits Only), Title (Between 1 and 4 Alpherabtic Characters, the allowed list is Dr, Lady, Lord, Miss, Mr, Mrs, Ms, Sir), Surname (Between 1 and 20 Alpherabtic Characters), Forname (Between 1 and 20 Alpherabic Characters), Sex (1 Character M or F upper or lower case), Date of Birth (in format DD/MM/YYYY), Vision Measurement (1 or 2 digits between 1 and 99). All the inputs have to be verified, if any verification fails then a suitable error message must be displayed and another prompt to re-enter the same item again. Then lastly the program needs to ask have you another customer details to enter, if yes to start again or exit if no.

    My mind is completly blocked
     
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    The first question I have is this:

    Is this to be displayed in a web-browser, or is it a standalone app?

    'Web design' suggests a browser, but Perl can equaly be used as an app.

    If as an app is this in a GUI style or a 'command line' style?

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. the1stefan

    the1stefan New Member

    3
    0
    1
    Harry thanks for your replay thread. To answer your questions. It's needs to be a standalone app and it's command line style.

    Stefan
     
  4. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    OK - now I have my DSL back working again....

    Without knowing exactly what is expected I suspect this is an 'early' excercise.

    You will be looking at pairs of lines like:
    print "Enter Customer Reference Number (4 Digits Only)\n";
    $custref = <STDIN>;

    You then need to remove the linefeed from the response, and then test against the rules given. The whole of the block could be enclosed in a while construct so that it repeats until the correct response is given (or the user dies of old age).

    Then surround the whole lot with another while block to repeat for a new customer.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  5. the1stefan

    the1stefan New Member

    3
    0
    1
    Harry,

    Just in case you did not recieve my private message to you. Here is the code I have come up with, I know that it's long winded. I hope that you can show me a more simpler way.

    $condition = 0;
    do{
    print("Please enter a four digit customer reference. ");
    chomp($customer_reference = <>);

    if($customer_reference =~ /^[0-9]{4}$/){
    print("\nThank you. Your customer reference is: $customer_reference\n");
    $condition = 1;
    }
    else{print("\nFOUR DIGITS PLEASE!.\n");
    }
    }while($condition == 0);

    $condition = 0;
    do{
    print ("\nWhat is your title? ");
    $title = <STDIN>;
    if ($title =~ /^[DLMS][adiorsy]{1,3}$/){
    print("\nThank you.\n");
    $condition = 1;
    }
    else{print("\nTry again.\nThe allowable list of titles is:\nDr, Lady, Lord, Miss, Mr, Mrs, Ms, Sir.\nFormat is Xxxx.\n");}
    }while($condition == 0);

    $condition = 0;
    do{
    print ("\nWhat is your surname? ");
    $surname = <STDIN>;
    if ($surname =~ /^[A-Z][a-z]{1,19}$/){
    print("\nThank you.\n");
    $condition = 1;
    }
    else{print("\nTry again.\nFormat is Xxxx.\n");}
    }while($condition == 0);

    $condition = 0;
    do{
    print ("\nWhat is your forename? ");
    $forename = <STDIN>;
    if ($forename =~ /^[A-Z][a-z]{0,19}$/){
    print("\nThank you.\n");
    $condition = 1;
    }
    else{print("\nTry again.\nFormat is Xxxx.\n");}
    }while($condition == 0);

    $condition = 0;
    do{
    print ("\nWhat is your sex? ");
    $sex = <STDIN>;
    if ($sex =~ /^[MmFf]{1}$/){
    print("\nThank you.\n");
    $condition = 1;
    }
    else{print("\nTry again.\nFormat is M or F.\n");}
    }while($condition == 0);

    $condition = 0;
    do{
    print("\nPlease enter your date of birth. ");
    $date_of_birth = <STDIN>;
    if ($date_of_birth =~ /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/){
    print("\nThank you.\n");
    $condition = 1;
    }
    else{print("\nTry again.\nFormat is DD/MM/YYYY.\n");}
    }while($condition == 0);

    $condition = 0;
    do{
    print("\nPlease enter your vision measurement. ");
    $vision_measurement = <STDIN>;
    if ($vision_measurement =~ /^[0-9]{1,2}$/){
    print("Thank you.\n");
    $condition = 1;
    }
    else{print("ONE or TWO DIGITS ONLY!!\n");}
    }while($condition == 0);
     
  6. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    I don't always use the machine that my account here points to - best, if you don't want to dump lots of code in the thread, is to use the PM system here.
    The general idea you use seems fine to me, however some specifics:
    Title: the test you use allows random other words such as 'Daa'. Best way to match a list like this, and avoid a huge chain of if and elsif, is to use a hash.
    Surname: This doesn't allow surnames such as O'Reilly and Whynn-Jones. And limits at 19 chars. The same goes for Forename (e.g. Anne-Marie), but you also allow no forename to be entered.
    Sex: I suspect you will get higher marks if you use the case-insensitive switch here.
    Date: This allows impossible dates, such as 40/15/2006!

    Finaly, you haven't put in the request for another customer!

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  7. Belmont

    Belmont Bit Poster

    22
    0
    21
    Stefan,
    I'd like to know how did you get on. Almost the same here, I'm stuck. Took me 2 days to work out the first script, another 2 days to write the second one and it's still incomplete. It's really hard to put the pieces together.

    Harry,
    much of the problems come from the question itself, as we don't have to be very specific. E.g. we only have to check if the date is in format DD/MM/YYYY, but they can be invalid (99/99/9999 etc.), and the names should be between 1-20 alphabetic characters.
    Anyway, you can find the questions (Perl TMA11A and 11B) on the "CIW Course in a Nutshell" website (I'm not sure if I could just put a link here).


    István
     
    Certifications: none related
    WIP: Master CIW Web Site Manager
  8. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    Weird - but I see what you mean!
    If you check my response I was saying that this hadn't been done - it only allowed 19 chars, not 20.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  9. Belmont

    Belmont Bit Poster

    22
    0
    21
    Yeah, you're right, I overlooked that.
     
    Certifications: none related
    WIP: Master CIW Web Site Manager

Share This Page

Loading...