On Aug 13, Darryl Schnell said:

>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++;
>      }

You should start $records at -1, not 0, because this ++ here makes you
BEGIN work at $table{$field}[1], not $table{$field}[0].  But you don't
need $records anyway.  Use push() like you should.

  push @{ $table{$field} }, $value;

There.  $records is useless.

>      chomp $value;
>      chomp $field;

Why are you chomping them?  And why AFTER the test?  If $field HAPPENED to
be "uid\n", you'd have a problem.

>      $table{$field}[$records] = "$value";

Why the quotes around $value?  You didn't put any around $field.  There's
no need for them here.

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

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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

Reply via email to