Kenton Brede wrote:
>
> I've written the following subroutine to snag the next available UID in
> the 700 range from /etc/passwd. I then use the return value with
> "useradd" to add a new user.
>
> The subroutine works fine. If no UID 700 is found it returns 700.
> It then returns the next available UID or adds 1 to the last UID in the 700
> block.
>
> Even though it is functional it seems a little clunky to me. If anyone
> has the time and inclination to point me to changes I could make I
> would appreciate it.
This will return the next UID or undef if one is not found:
sub get_uid {
my ( $start, $end ) = @_;
--$start;
defined getpwuid $start or return $start while ++$start <= $end;
return;
}
print get_uid( 700, 799 ), "\n";
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>