0 Replies - 1439 Views - Last Post: 31 July 2007 - 12:05 PM

#1 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6747
  • View blog
  • Posts: 31,229
  • Joined: 10-May 07

Generic Menu with sub

Posted 31 July 2007 - 12:05 PM

Description: Use the sub function to create a looping menu.
#!/usr/bin/perl
# Written by #2pencil for  7/31/2007
# Description: Generic Menu with sub

print "n======= Automated menu";
print "nWritten by #2pencil for  7/31/2007";
print "n=======nnn";
$ch=1;
if($ch < 10){ menu($ch); }
else { print "Don't do it!n"; }

sub menu {
     $ch=0; # whatever it was, we don't care!
     do {
          for($i=0;$i<35;$i++) {
               print("*");
          }
          print "n    1.) Item 1";
          print "n    2.) Item 2";
          print "n    3.) Item 3";
          print "n    4.) Item 4";
          print "n    5.) Item 5";
          print "n    6.) exitn";
          for($i=0;$i<35;$i++) {
               print("*");
          }
          print "nnPlease enter your choice: ";
          $ch=;
          chop($ch);
          check($ch);
     } while $ch=0;
}

sub check {
      if($ch == '6') {
           print "nnExiting";
           exit(0);
      }
      if($ch == '1') {
           print "nnLaunching Item 1n";
      }
      if($ch == '2') {
           print "nnLaunching Item 2n";
      }
      if($ch == '3') {
           print "nnLaunching Item 3n";
      }
      if($ch == '4') {
           print "nnLaunching Item 4n";
      }
      if($ch == '5') {
           print "nnLaunching Item 5n";
      }
      menu($ch);
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1