On Sat, Feb 07, 2004 at 02:08:26PM -0800, John W. Krahn ([EMAIL PROTECTED]) wrote: > 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: >
Thanks for your response. Where do I begin asking questions about this one, hehe. > sub get_uid { > my ( $start, $end ) = @_; > --$start; > defined getpwuid $start or return $start while ++$start <= $end; > return; > } > > print get_uid( 700, 799 ), "\n"; I'll attempt to translate this into code. my $start = 700; my $end = 799; while(++$start <= $end) { if (defined(getpwuid($start)) { return $start; } else { return $start if ($start > --$start); } OK, I know that is probably way off. I'm having trouble wrapping my mind around this one. Kent -- "Efficiency is intelligent laziness." -David Dunham -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>