neilh has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use Net::LDAP; my $givenname="Neil"; my $sn="Hunt"; my ($ldap,$mesg); &ldap_search; sub ldap_search { &ldap_bind; my $base="ou=People,dc=btester,dc=com,dc=au"; $mesg = $ldap->search ( base => $base, filter => "(&(cn=$givenname $sn))"); if ($mesg->count == 0) { print "Hi!\n"; } else { print "Content-type: text/html\n\n"; print "<title>Already Exists</title>"; print "$givenname $sn already exists"; print "<p>"; print "Go <a href=\"../addemp.html\">Back</a>"; } } sub ldap_bind{ my $ldap_server="argyle"; my $user="cn=Directory Manager"; my $pass="<password>"; return $ldap = Net::LDAP->new( $ldap_server ) or die "$@"; return $mesg = $ldap->bind( "cn=Directory Manager", password => "secretsecret" ); }
Update:
Thanks Zaxo. I applied the changes you suggested. Not only does my code work nicely, I learnt so much more about how a subroutine works.
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing parameters between subroutines
by Zaxo (Archbishop) on Aug 10, 2004 at 02:24 UTC | |
by neilh (Pilgrim) on Aug 11, 2004 at 00:28 UTC |