On Sunday, September 1, 2002, at 12:46 , ANIDIL RAJENDRAN wrote:
[..]
> $passwd = "/etc/passwd";
> $skip = 60000;
> open(PW,$passwd) or die "Can't open $passwd:$!\n";
> while (<PW>){
>     @fields = split(/:/);
>     next if $fields[2] > $skip;
>     $highestuid = ($highestuid < $fields[2]) ? $fields[2] : $highestuid;
> }
> close(PW);
> print "The next available UID is " . ++$highestuid . "\n";

it looks like you have somewhat mutually conflicting goals.

you might want to declare your $highestuid outside of
the loop....

something like

        #
        # let us initialize this to a silly value
        #
        my $highest_uid= -1;

        while(<PW>)
                my @fields = split(/:/);
                #
                # good choice here - since if the passwd file
                # is not linear you will need to see all records
                #
                next if $fields[2] > $skip;
                #
                # update $highestuid if it smaller - why
                # re-assign it to itself???
                #
                $highest_uid = $fields[2]
                        if  ($highest_uid < $fields[2]);
        }

        # now since we scoped $highest_uid outside of the
        # while block it will have what ever it got set to...

        print "The next available UID below $skip is " . ++$highestuid . "\n";


ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to