Код удаления объектов
# Code That Deletes Objects
use strict;
use Net::LDAP;
# BEGIN CALLOUT A
BEGIN COMMENT
# Customize for your environment.
# Настройте для вашего окружения.
my $dc = ?dc1?;
my $user = ?administrator@mycorp.com?;
my $passwd = ?Adminpasswd?;
my $parent_dn = ?ou=Contacts, dc=mycorp, dc=com?;
# END CALLOUT A
BEGIN COMMENT
# Connect and authenticate.
# Соединение и авторизация.
END COMMENT
my $ldap = Net::LDAP->new($dc) or die «$@
»;
my $rc = $ldap->bind( $user, password => $passwd);
die $rc->error if $rc->code;
# BEGIN CALLOUT B
BEGIN COMMENT
# Find all contact objects in $parent_dn.
END COMMENT
my $search = $ldap->search (
	base => $parent_dn, 
	scope => ?one?, 
	filter => «(objectClass=contact)», 
	attrs => [?cn?], 
);
die $search->error if $search->code;
# END CALLOUT B
# BEGIN CALLOUT C
BEGIN COMMENT
# Delete all matching objects.
END COMMENT
my $count = 0;
foreach my $entry ($search->entries) {
	$rc = $ldap->delete( $entry->dn );
	if ($rc->code) {
		print «Delete failed for «, $entry->get_value(?cn?), «: «, $rc->error, «
»;
	}
	else {
		$count++;
		print «Delete successful: «, $entry->get_value(?cn?), «
»;
	}
}
print «Total successfully deleted: $count
»;
# END CALLOUT C
$ldap->unbind;