http://www.perlmonks.org?node_id=1026775

anakin30 has asked for the wisdom of the Perl Monks concerning the following question:

i received below error when i run my code

The script generate result if the input file contains less then 10 users, however the error trigger if the input file contain more than 10 users

i appreciate if anybody can advice, how to rectify the error

Can't call method "dn" on an undefined value at ExportAttribute2.pl line 45, <TEST> line 991.

i have marked the error , line number with the comment # in the below code for your reference

$TEST = 'C:\Perl\project\export\20130402\test.txt'; #$TEST = 'C:\Perl\project\export\20130402\users.txt'; $outputfile = 'C:\Perl\project\export\20130402\result.csv'; open (FH, ">$outputfile") or die "$!"; print FH "uid,SN,GIVENNAME,uniSALUTATION,Displayname\n"; my $adHost = "ldap.uni.com"; my $adUsr = "uid=myscript,ou=users,o=uni.com"; my $adPass = "Myscript2012"; my $query = "(objectclass=uniperson)"; my @attrs = qw(uid SN GIVENNAME uniSALUTATION Displayname); my $ldap = Net::LDAP->new($adHost) or die $!; my $mesg = $ldap->bind($adUsr, password =>$adPass); my $page = Net::LDAP::Control::Paged->new( size => 1000 ) or die $!; open(TEST) or die("Could not open log file."); foreach $line (<TEST>) { chomp($line); #print "$line \n";#} #while (1) { my @args = ( base => 'ou=users,o=uni.com' , scope => 'sub', filter => +$line, attrs => \@attrs, control => [ $page ],); $mesg = $ldap->search ( @args ) or die $!; #while (my $entry = $mesg->shift_entry() ) { #uid,SN,GIVENNAME,uniSALUTATION,Displayname my $entry = $mesg->shift_entry(); my $entrydn = $entry->dn(); #line 45 the error triggered here my $uid = $entry->get_value ('uid'); my $SN = $entry->get_value ('SN'); my $GIVENNAME = $entry->get_value ('GIVENNAME'); my $uniSALUTATION = $entry->get_value ('uniSALUTATION'); my $Displayname = $entry->get_value ('Displayname'); print FH "$uid,$SN,$GIVENNAME,$uniSALUTATION,$Displayname\n"; }

please advice me how to get rid of the error above. I need to export 3000 users based on userID from input file with the selected attributes from LDAP using this script"