Fellow monks I was hoping some of you could take a look at a piece of code I wrote earlier today and give me some feedback on it.

The code will provide a Unix user with a very short menu to either establish a ppp connection or logoff the system. The code will be run out of the users .login. I am wondering if there is a better way to accomplish this task then what I have come up with and if anyone can see any ways that I have missed to break out of this menu. Thanks for any help and suggestions you can offer.

#!/usr/local/bin/perl -w use strict; sub main_block { my $username = getlogin; my $ppid = getppid; my $result = generate_menu($username); until ($result == 1 || $result == 2) { print "Invalid option.\n"; sleep 2; $result = generate_menu($username); } user_choice($result, $ppid); } sub generate_menu { my $username = shift; system("clear"); print "Welcome $username\n\n"; print "Please chose from the following options:\n"; print "1) Establish PPP Session\n"; print "2) Logoff\n"; print "------------------------\n"; print "Choice: "; chomp (my $result = <STDIN>); return $result; } sub user_choice { my ($result, $ppid) = @_; if ($result == 1) { print "\nServer to connect to: "; chomp (my $server = <STDIN>); ppp_connect($server); } else { kill 9 => $ppid; } } sub ppp_connect { my $server = shift; system("clear"); system("ppp -direct $server"); main_block; } $SIG{INT} = 'IGNORE'; $SIG{TSTP} = 'IGNORE'; main_block;


-Prime

In reply to Shell Menu Code Review by PrimeLord

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.