Thanks. Using the pop-entry line does in fact return all the DN's from the 
input file. Unfortunately, once I try to print the next two lines and insert 
more code to iteratively lookup and print a dn, everything breaks. The goal is 
to print to a file in the following order: 



search dn result from input1 

changetype: modify 

replace: manager 

manager: "search dn result from input 2"                     ;i've commented 
this code till i get the first 3 lines working 



Here's the code I have. Using your recommendation failed with the below errors 
(tried dn and $dn). Thanks for looking, again. 



#! perl 

use strict; 
use warnings; 
use diagnostics; 

use Net::LDAP; 
use Net::LDAP::Entry; 
use Net::LDAP::Search; 
use Net::LDAP::LDIF; 

open PERSON, "<", "ou3" or die "Cannot open 'ou3': $!"; 
open MGR, "<", "ou8" or die "Cannot open 'ou8': $!"; 
open OUT, ">", "ldif3.ldif" or die "Cannot open 'ldif3.ldif': $!"; 

my $HOST = "1"; 
my $ADMIN = "cn=admin,DC=corp"; 
my $PWD = "0"; 
my $BASEDN = "DC=corp"; 

my $ldap = Net::LDAP->new("$HOST", port=>389) or die "$@"; 
my $dn = $ldap->bind("$ADMIN", password=>"$PWD"); 
my $mgrdn = $ldap->bind("$ADMIN", password=>"$PWD"); 
my @attr = "1.1"; 
my $result = Net::LDAP::LDIF->new( "ldif3.ldif", "a", wrap=>40 ); 
my $entry; 
my $entry2; 



while (<PERSON>){ 
chomp; 
$dn = $ldap->search( #return only the employeeID DN 
        base => "$BASEDN", 
        filter => "(&(objectClass=user)(employeeID=$_))", 
        scope => "sub", 
        attrs => ['1.1'] 
        ); 

        $dn->code && die $dn->error; 

#        $entry = $dn->pop_entry; 
        $entry->dn; 
        print $result->write_entry($entry); 
        print OUT "changetype: modify", "\n"; 
        print OUT "replace: manager", "\n"; 
} 
#continue; 
#while ($mgr){ 
#while (<MGR>){ 
#chomp; 
#$mgrdn = $ldap->search( #return only the manager DN 
#        base => "$BASEDN", 
#        filter => "(&(objectClass=user)(employeeID=$_))", 
#        scope => "sub", 
#        attrs => [...@attr], 
#        ); 
#        $mgrdn->code && die $mgrdn->error; 
#        foreach $entry2 ($mgrdn->entries) { $entry2->dump; } 
#        #$entry2 = $mgrdn->pop_entry(); 
#        #$result->write_entry($entry2); 
#        #print OUT $entry2; 
#        #print OUT "manager: $entry2", "\n"; 
#} 
#} 

$dn = $ldap->unbind;  #session ends 

close OUT or die "Cannot close in-memory file: $!"; 
close MGR or die "Cannot close in-memory file: $!"; 
close PERSON or die "Cannot close in-memory file: $!"; 







Here's the errors: 



C:\Temp10>c:\perl\bin\perl ldif3a.pl 
Can't call method "dn" on an undefined value at ldif3a.pl line 56, <PERSON> 
        line 1 (#1) 
    (F) You used the syntax of a method call, but the slot filled by the 
    object reference or package name contains an undefined value.  Something 
    like this will reproduce the error: 

        $BADREF = undef; 
        process $BADREF 1,2,3; 
        $BADREF->process(1,2,3); 

Uncaught exception from user code: 
        Can't call method "dn" on an undefined value at ldif3a.pl line 56, 
<PERS 
 at ldif3a.pl line 56 

C:\Temp10>edit ldif3a.pl 

C:\Temp10>c:\perl\bin\perl ldif3a.pl 
Can't call method "Net::LDAP::Search=HASH(0x1874a24)" on an undefined value at 
        ldif3a.pl line 56, <PERSON> line 1 (#1) 
    (F) You used the syntax of a method call, but the slot filled by the 
    object reference or package name contains an undefined value.  Something 
    like this will reproduce the error: 

        $BADREF = undef; 
        process $BADREF 1,2,3; 
        $BADREF->process(1,2,3); 

Uncaught exception from user code: 
        Can't call method "Net::LDAP::Search=HASH(0x1874a24)" on an undefined 
va 
 at ldif3a.pl line 56 


Reply via email to