From: Chris R. <chr...@me...> - 2000-11-24 08:44:21
|
Terence Ho <ter...@ka...> wrote: > I have code the follwing and want to get the result of the compare : > > part of the code : > > $mesg = $ldap->compare(dn => 'cn=test2,o=kader,c=hk', > attr => 'cn', > value => 'test2' > ); > print $mesg; > print "not 4" if $mesg->code; > print "ok 4\n"; > > result : > Net::LDAP::Compare=HASH(0x830dbd4)not 4ok 4 > > Can anyone tell me where I can find more info or just give me a short > example. > > Best regards, > Terence > The $mesg value returned by $ldap->compare is an object, and printing an object (like you are) will usually not give you the results you desire. What you need to do is to look at the code in $mesg->code; it'll be either LDAP_COMPARE_TRUE, or LDAP_COMPARE_FALSE, or something else if Bad Things Happened. Try this: use Net::LDAP::Util qw(ldap_error_name); use Net::LDAP::Constant qw(LDAP_COMPARE_TRUE LDAP_COMPARE_FALSE); $mesg = $ldap->compare(...); # As before if ($mesg->code == LDAP_COMPARE_TRUE) { print "ok\n"; } elsif ($mesg->code == LDAP_COMPARE_FALSE) { print "not ok\n"; } else { print "error " . ldap_error_name($mesg->code) . "\n"; } Cheers, Chris |