sub ldapassert { my $mesg = shift; my $action = shift; if ($mesg->code) { die "An error occurred $action: " .ldap_error_text($mesg->code)."\n"; } return $mesg; } my $result = ldapassert($ldap->bind(), "binding to the server");