Prince Mavi 写道: > Hi folks > > I am new to perl. this is my first real program in perl. > The program is not doing what i intend it to do. > The problem in nut shell is that: > I expect to see the menu first and then input my choice. > but > the program asks for my choice first and then displays the menu > > Please have a look and see what am i doing wrong. > > Thanks a ton for your time guys. > > > code > ---------------------------------------------------------- > #!/usr/bin/perl > use strict; > use warnings; > > sub dispBlanks { > print "\n\n"; > } > > sub clrScr { > system("clear"); > } > > sub dispMenu { > clrScr; > print "\n\n=== Student Manage Pro ===\n"; > print "1. Display all students\n"; > print "2. Display a particular student\n"; > print "3. Add a new student\n"; > print "4. Delete a student\n"; > print "0. Exit\n"; > print "Please choose one of the options\n"; > } > > while (1) { > dispMenu > my $choice = <STDIN>; > chomp($choice); # to remove newline > print "you chose $choice"; > dispBlanks; > } > ---------------------------------------------------------- > > > 1 #!/usr/bin/perl -w 2 use strict; 3 use warnings; 4 5 sub dispBlanks { 6 print "\n\n"; 7 } 8 9 sub clrScr { 10 system("clear"); 11 } 12 13 clrScr;/ #<<<<===== 14 sub dispMenu { 15 print "\n\n=== Student Manage Pro ===\n"; 16 print "1. Display all students\n"; 17 print "2. Display a particular student\n"; 18 print "3. Add a new student\n"; 19 print "4. Delete a student\n"; 20 print "0. Exit\n"; 21 print "Please choose one of the options\n"; 22 } 23 24 my $choice = 1; 25 while ($choice) { 26 dispMenu; 27 chomp($choice = <STDIN>); 28 print "you chose $choice"; 29 dispBlanks; 30 }
-- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/