Below you will find an ldapsearch subroutine that I am trying to
perform. The problem I cannot figure out is the last print statement:

print LOG "DEBUG:$table{gecos}[$cnt]:$table{uid}[$cnt]\n";

It's suppose to print out data like below:

Testus1:000111
Testus2:000112
Testus3:000113
Etc.

However it appears to be doing this:

:000111
Testus1:000112
Testus2:000113
Testus3:


I think it has something to do with my records++ line however I cannot
seem to pinpoint the problem. Anyone have any other ideas that may
resolve this small stupid problem.

Thanks,
Darryl


sub ldap_srch {
  my $limit = "20";
  my $emailname = shift;
  $ldap_con = new Net::LDAPapi($host);
  if ($ldap_con == -1) { die "Unable to Open LDAP Connection to $host";
}
  $status = $ldap_con->bind_s("cn=Directory Manager", $passwd);
  if ($status != LDAP_SUCCESS) { die $ldap_con->errstring; }
  @attrs = ();
  $filter = "uid=*$emailname*";
  $status =
$ldap_con->search_s($dn,LDAP_SCOPE_SUBTREE,$filter,\@attrs,0);
  if ($status != LDAP_SUCCESS) { die $ldap_con->errstring; }
  %ldap_results = %{$ldap_con->get_all_entries};
  $ldap_con ->unbind;
  $records = 0;
  if ($cnt eq "") { $cnt=0; }
  foreach $line (keys %ldap_results) {
    foreach $field (sort keys %{$ldap_results{$line}}) {
      $value = "@{$ldap_results{$line}{$field}}";

      if ($field eq "uid") {
        $records++;
      }
      
      chomp $value; 
      chomp $field;
      $table{$field}[$records] = "$value";
    }
  }
  if ($records < $limit) { $limit = $records; }
  open (LOG, ">output");
  while ( $cnt <= $limit ) {
    print LOG "DEBUG:$table{gecos}[$cnt]:$table{uid}[$cnt]\n";
    $cnt++;
  }
  close (LOG);
}

-----
Anyone who believes exponential growth can go on forever in a finite
world is either a madman or an economist. --Kenneth Boulding

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

Reply via email to