Thank you Perl brothers. I have a question regarding the use of the Readline function after previously using the Read function. The following script allows the user to enter a name using <STDIN> (line 10) and then allows entry of the user's social security number using the Read function. However, as you go to line 36 where the user is prompted for the class elective number the program does not allow for user entry. It skips right onto the next line not pausing for user entry. Can Read and <STDIN> be used in the same program or does something extra have to be done in order for one not to interfere with the other. It looks like the <STDIN> on line 37 has something already so that's why I'm not prompted for user input. I'm using Perl 5.10 on Win32 platform and running my script through Eclipse. Thank you.

elective 2.pl
1 use PadWalker qw(peek_my peek our peek sub closed over); 2 3 print <<EOF; 4 REGISTRATION INFORMATION FOR SPRING QUARTER 5 Today's date is Wed Apr 19 17:40:19 PDT 2007 6 Please enter the following information: 7 Your full name: 8 EOF 9 10 $name = <STDIN>; 11 print "What is your Social Security Number (xxx-xx-xxxx): "; 12 read(STDIN, $social number, 11); 13 print "$social_number\n"; 14 if ($social number !~ m/"[\d] {3}-[\d] {2}-[\d] {4)$/) { 15 print "Not a valid social."; 16 exit; 17 } 18 else { 19 20 print <<INFO; 21 Your address: 22 Street: 1424 Hobart st. 23 City, State, Zip: Chico, CA 95926 24 25 "EDP" NUMBERS AND ELECTIVES: 26 INFO 27 28 %elective = ( "2CPR2B" => "c Language", 29 "lUNX1B" => "Intro to UNIX", "3SH414" => "Shell Programming", "4PL400" => "Perl Programming" ); 30 31 while( ($key,$value) = each(%elective) { 32 print "$key I $value\n"; 33 print x 30, "\n"; 34 } 35 } 36 print "\nWhat is the EDP number of the course you wish to take ? +:"; 37 chomp ($class_id = <STDIN>; 38 print "$class_id\n"; 39 print "You will be taking ",$elective{$class id}," this semester +.\n" 40 if exists $elective{$class id}; 41 print "This course number does not exist.\n" 42 if not exists $elective {$class id}; OUTPUT: REGISTRATION INFORMATION FOR SPRING QUARTER Today's date is Wed Apr 19 17:40:19 PDT 2007 Please enter the following information: Your full name: John Smith What is your Social Security Number (xxx–xx–xxxx): 101-42-4135 101-42-4135 Your address: Street: 1424 Hobart St. City, State, Zip: Chico, CA 95926 "EDP" NUMBERS AND ELECTIVES: 1UNX1B | Intro to UNIX ______________________________ 4PL400 | Perl Programming ______________________________ 2CPR2B | C Language ______________________________ 3SH414 | Shell Programming ______________________________ What is the EDP number of the course you wish to take ?: This course number does not exist.

In reply to Read & Readline Functions by Cmdr Colstel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.