Perl and LDAP

Hi Perl Guys

I am in need of your knowledge as i am a complete newbie and perl

I need to do pull all the groups from LDAP , and then look at the GID's and if they are not set check for the next available ( i,e increment ) and apply it

I have done this so far that prints out all the gorups and their Gud
but i am unsure of what to do next?


#!/usr/bin/perl


use strict;
use warnings;
use Data::Dumper;
use Net::LDAP;
use DBI;


# get list of job groups from AD, create array @ldapgroups
my $ldap = Net::LDAP->new('ad.dneg.com') or die "$@";
my $mesg = $ldap->bind;
my $result = $ldap->search( base => "ou=Groups,dc=ad,dc=spa,dc=com", 
	                           filter => "cn=*",
                               attr  => ['DisplayName,gidNumber']);



my @entries = $result->entries;

my $previous_gid = -1;

my $entr;
foreach $entr ( @entries ) {
print "DN: ", $entr->dn, "\n";
my $attr;
  foreach (qw/ name gidNumber / ) {
     print "  $_ : ", $entr->get_value ( $_ ) ,"\n";
   }
  print "#-------------------------------\n";
 };


Thanks

Run it through sort -r = reverse and line to get the max ?