uid script help

i need a script to process a password file and based on the UIDs in the password file, generate the new UID that is 1 greater than the highest uid.
i have some script logic but i dont really understand it. any help?

    #!/usr/bin/perl
   
  ##########################################
    # ITEC 400
  # Script name: newuid.pl
  # Case Number 1: ./newuid.pl small_passwd
  # The small_passwd file is located ~/public_html/itec400/Misc
  # The name of the file must be specified on the command line.
  # Functionality: The newuid.pl script reads the uids in the small_passwd
  # file. The script determines the highest numbers uid currently
  # in use, and adds one to it for the next user.
  ##############################################
   
  for $XXXX(@ARGV) {
  $counter++;
  }
   
  if ($XXXXXXX != 1) {
  print "Error. Need one argument.\n";
  }
   
  if ($XXXXXXX == 1) {
   
  $flag = 0;
   
  exec `XXX -f3 -d":" /export/home/dandrear/public_html/itec400/Misc/$XXXX[]> "uidoutput"`;
   
  open (reader, "uidoutput");
   
  while ($line = <XXXXXX>) {
   
  $firsttest = $XXXX;
   
  if ($XXXX == 0) {
  $secondtest = $XXXXXXXXX;
  } # end if
   
  $flag = 1;
   
  if ($secondtest < $XXXXXXXXX) {
   
  $secondtest = $XXXXXXXXX;
   
  } #end if
   
   
  } # end while
   
  $newIDNum = $XXXXXXXXXX + 1;
   
  print "The new User ID number is ";
  print $XXXXXXXX;
  print "\n";
   
  } # end if
   
  

Quick comment -

Accounts like "nobody" or "noaccess" frequently have very high UID's while normal users are given much lower ones. Simply taking the very highest UID + 1 may not be what you want. You may want to rethink your requirements.

Simple awk script --

 newuid=$(awk -F: ' {max=(max<$3)?max=$3: max} END{print max+1}' /etc/passwd)

thank you for your input but I need uid +1. im doing this script for a class and that is the requirement.

That is what the script does +1.

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.