If you find yourself having problems with nested loops, it helps to indent your code so the structure becomes clearer:
while (<PERSON>) { chomp; $dn = $ldap->search( #return only the employeeID DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr] ); next unless $dn; # Make sure something is returned while( my $entry = $dn->pop_entry() ) { $result->write_entry($entry); if ( $result != /dn:/ ) { print OUT (@lines); } while (<MGR>) { ...
could be reindented as
while (<PERSON>) { chomp; $dn = $ldap->search( #return only the employeeID DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr] ); next unless $dn; # Make sure something is returned while( my $entry = $dn->pop_entry() ) { $result->write_entry($entry); if ( $result != /dn:/ ) { print OUT (@lines); } while (<MGR>) { ...
So, you'll see that once you've read to the end of MGR, you'll still have lines in PERSON. Maybe you want to look up data from the contents of MGR? Then a hash is a better structure:
my %manager; while (<MGR>) { $manager{ $_ } = $ldap->search(...); # return only the manager DN }; while (<PERSON>) { ... # you never seem to use the information from MGR here... };
In reply to Re^7: Perl Builds an LDIF
by Corion
in thread Perl Builds an LDIF
by rfransix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |