Re: get_uid sub critic
From: John W. Krahn (krahnj_at_acm.org)
Date: 02/07/04
- Next message: R. Joseph Newton: "Re: my in the perl syntax"
- Previous message: James Edward Gray II: "Re: Method invocation arrow (LPORM)"
- In reply to: Kenton Brede: "get_uid sub critic"
- Next in thread: Kenton Brede: "Re: get_uid sub critic"
- Reply: Kenton Brede: "Re: get_uid sub critic"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Sat, 07 Feb 2004 14:08:26 -0800
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
- Next message: R. Joseph Newton: "Re: my in the perl syntax"
- Previous message: James Edward Gray II: "Re: Method invocation arrow (LPORM)"
- In reply to: Kenton Brede: "get_uid sub critic"
- Next in thread: Kenton Brede: "Re: get_uid sub critic"
- Reply: Kenton Brede: "Re: get_uid sub critic"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|