Hello all,

I am having trouble displaying my LDAP search results using sorting.  I am 
opening a text file parsing out the UID and performing a LDAP search 
filtering using this UID, but I'm not getting the results, just blank 
lines.  Below is the script.  I'm not sure if I am using the 
Net::LDAP::Control::Sort correctly.


use Net::LDAP qw(:all);
use Net::LDAP::Util qw(ldap_error_text);
use Net::LDAP::Control::Sort;
use Net::LDAP::Constant qw(LDAP_CONTROL_SORTRESULT);

my $ldapObject = Net::LDAP->new('ldap.host.com') || die "$@";
my $sorted = Net::LDAP::Control::Sort->new(
                order => "departmentnumber"
        );

open(FH, "< myfile.txt") || die "$@";


while (<FH>)
{
        my $line = $_;
        $counter++;

        if ("$counter" < '7')
        {
                next;

        } else {

                if ($line =~ /^Total/)
                {
                        $total_line = "$line";
                        next;
                } else {
                        chomp($line);
                        $line =~ s/\t\t*/ /g;
                        $line =~ s/\"\"*//g;
                        $line =~ s/\,\,*//g;
                        $line =~ s/^(\n)//;
                        ($iid, $domain, $session, $minutes, $cost) = 
split(/  */, $line);
                        $sr = $ldapObject->search(
                                                base=> 'O=company',
                                                scope=> 'sub',
                                                filter=> 
"(&(objectclass=jwsPerson)(uid=$iid))",
                                                control => [ $sorted ]
                        );

                        ($resp) = $sr->control( LDAP_CONTROL_SORTRESULT );

                        @entries = $sr->entries;
                        foreach $entry (@enttries)
                        {
                                $uid = $entry->get_value('uid');
                                $fname = $entry->get_value('givvenname');
                                $lname = $entry->get_value('sn');
                                $location = $entry->get_value('l');
                                $deptnum = 
$entry->get_value('departmentnumber');

                        print 
"$uid\t$fname\t$lname\t$location\t$deptnum\n";

                        }


                }
        }
}

close(FH);

Reply via email to