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

Wonder if anyone can help me fix the following. I try to test LDAP server status by using the module Net::LDAP, I wrote the following code, executed and got the following error message.

Undefined subroutine &Net::LDAP called at ./ldap.pl line 4

When I use Unix command, I typed: ldapsearch -h host.edu "cn=administrator", it returned results, which means the server is up. What I really need is to write a perl script to test the LDAP server status. Thank you.

################################## use Net::LDAP; use strict; my $ldap = Net::LDAP->('host.edu', port => '389'); $ldap -> bind; my $mesg = $ldap -> search(base => "cn = administrator"); use Net::LDAP::Util qw(ldap_error_text); die ldap_error_text($mesg->code) if $mesg->code;

Replies are listed 'Best First'.
Re: Undefined subroutine
by AgentM (Curate) on Mar 12, 2001 at 23:04 UTC
Re: Undefined subroutine
by BlueLines (Hermit) on Mar 13, 2001 at 00:43 UTC
    AgentM is correct. You are calling Net::LDAP, which is a subroutine named LDAP in the Net module.

    You want the following:
    my $ldap = new Net::LDAP();


    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.

      when I added new at line 5, another error message pop up (see below). Do you have similar examples? Thanks.

      Undefined subroutine &main:: called at ./ldap.pl line 5