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"


In reply to Perl LDAP script error "Can't call method "dn" on an undefined value" by anakin30

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.