On 16/12/03 7:06 am, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:
> Hello,
> following perl script, using Net::LDAP 0.30 , sometimes causes following
> problem :
> ---------------------------------------
> $ldap = Net::LDAP->new('<ldap-server>) or &DEBUG("Failed to open LDAP
> connection : $@");
> $ldap->bind or &DEBUG("Failed to bind to LDAP : $@");
That doesn't test the bind worked, BTW. The bind method returns a
Net::LDAP::Message object which you need to query, similar to the search
method (except that returns a subclass of Message.)
> &DEBUG("LDAP connection opened ") ;
>
> undef $mesg ;
> $mesg = $ldap->search( base => "o=tietoenator corp", scope => "sub",
> filter => "(&(cn=$fullname)(ba=Processing & Network))" );
The '&' in 'Processing & Network' should be escaped, as it is a special
character in the string representation of LDAP filters. You ought to be
careful that $fullname is properly escaped too.
> if ( defined $mesg )
> {
> if ( $mesg->code == LDAP_SUCCESS ) # no errors
> { $cnt = $mesg->count; }
> else { $cnt = 0; }
> }
> ---------------------------------------
> The above script is continuously , about once each minute, doing the
> above search, and most of the times everything works ok.
>
> However, script sometimes exits with error message
> 'Can't call method "code" without a package or object reference at
> /home/niv/net_updater.pl line 205, <GEN4> line 52.'
>
> It seems to me that the "defined" test is not enough to make sure that
> $mesg is usable as an object.
Well, it is meant to be! What perl version are you using on what platform?
Cheers,
Chris