in reply to Perl Builds an LDIF

Most likely, you have read in line-ending characters when you read the PERSON file.

ldap probably cannot find the person, and returns an empty $dn.

Fix by:

while (<PERSON>) { chomp; # Strip trailing line-ending #.. process ldap stuff
Your query would look much prettier, and be easier to answer if you followed Writeup Formatting Tips, and used code tags.

Update: Fixed typo, and adding this recommendation:
Use the 3-parameter doem of OPEN:

open PERSON, "<", "ou3" or die "Cannot open 'ou3': $!";

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Replies are listed 'Best First'.
Re^2: Perl Builds an LDIF
by Anonymous Monk on Jun 15, 2010 at 14:53 UTC
    Humble and grateful, your insightful observation to chomp has revived this perl program to a higher level. The resultant output remains divided by a dash line; and Data::Dumper and print OUT, these lines are not working as buildAD.ldif only gets ,,bless'' coding structure. foreach $dn ($dn->entries) { push @attr, $dn->dump; } #$Data::Dumper::Purity = 1; #$Data::Dumper::Deepcopy = 1; my $ev = Data::Dumper->Dump($dn, qw(dn)); print OUT $ev; }
Re^2: Perl Builds an LDIF
by Anonymous Monk on Jun 15, 2010 at 15:05 UTC

    Humble and grateful, your insightful observation to chomp has revived this perl program to a higher level. The resultant output remains divided by a dash line still; and Data::Dumper and print OUT, these lines are not working as buildAD.ldif only gets ,,bless'' coding structure.

    foreach $dn ($dn->entries) { push @attr, $dn->dump; } #$Data::Dumper::Purity = 1; #$Data::Dumper::Deepcopy = 1; my $ev = Data::Dumper->Dump($dn, qw(dn)); print OUT $ev; }

      Grateful, I return with good news. I have removed the dashes, unwrapped the search result and sent to a file (although I had to hardcode the filename. My next plea is to discover why Net::LDAP::LDIF only writes the last result to FILE, I wish all results to write to FILE. Here's the updated code.

      while (<PERSON>){ chomp; $dn = $ldap->search( #return only the employeeID DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => ['1.1'] ); Net::LDAP::LDIF->new( "buildAD.ldif", "w", wrap=>40 )->write( $dn->ent +ries ); }

        Happy, I return with more good news. I have been able to send all search results to a file. However, I wish to iteratively search on PERSON values, writing the result to FILE, as well as the print OUT statements, to build an LDIF. This is not happening. Instead, the print OUT statements are clobbering FILE, overwriting the search results. Here's the code, thanks.

        while (<PERSON>){ chomp; $dn = $ldap->search( #return only the employeeID DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => ['1.1'] ); my $result = Net::LDAP::LDIF->new( "buildAD.ldif", "a", wrap=>40 ); while( my $entry = $dn->pop_entry() ) { $result->write_entry($entry); } print OUT "changetype: modify"; print OUT "replace: manager"; print OUT "manager: dn","\n"; } $dn = $ldap->unbind; #session ends