Not beautiful, but better, I hope:
#!/usr/local/bin/perl use strict; use warnings; use Term::ReadKey qw(ReadMode ReadLine); use IPC::System::Simple qw(system); my $choice=0; GETCHOICE: { print "Admin Menu\n"; print "To add a user, press 1\n"; print "To delete a user, press 2\n"; print "To add a group, press 3\n"; print "To delete a group, press 4\n"; print "To exit this menu, press 5\n"; print "Please choose an option: "; chomp($choice=<STDIN>); redo GETCHOICE if $choice < 1 || $choice > 5; } print "You chose option: $choice\n"; if($choice == 1) { my $nUsername; GETUSER: { print "What is new users name? "; chomp($nUsername=<STDIN>); # check that new user name is a string if($nUsername!~/^[A-Za-z0-9]+$/) { print "New username must be a string.\n"; redo GETUSER; } } # check to see if user exists if(defined getpwnam($nUsername)) { print "User exists\n"; } else { ## FIXME delete "echo" system("echo","/usr/sbin/adduser","--home", "/home/$nUsername","--gecos",$nUsername); # get new user password my ($nPassword,$nPasstest); GETPASS: { ReadMode("noecho"); print "Please add password: "; chomp($nPassword=ReadLine(0)); print "\n"; print "Please re-enter password: "; chomp($nPasstest=ReadLine(0)); print "\n"; ReadMode("restore"); redo GETPASS if $nPassword ne $nPasstest; } print "Please enter group for user: "; chomp(my $nGroup=<STDIN>); # add user to group if(defined getgrnam($nGroup)) { # check to see is group exists print "$nGroup already exists\n"; # add user to group system("echo","groupadd",$nGroup); } else { # if group does not exist create group system("echo","groupadd",$nGroup); print "$nGroup has been added.\n"; } } }

In reply to Re: unix to perl questions by Anonymous Monk
in thread unix to perl questions by deyaneria

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.