I would propose rather than incrementing a letter index you could just use
'a'..'z' range operator.
This is how I would code the example.
#!/usr/bin/perl
use Modern::Perl;
use Net::LDAP;
# Connect and bind
my $ad = Net::LDAP->new("
ad.wjgilmore.com") || die "Could not connect!";
$ad->bind( '
ad-web@ad.wjgilmore.com', password => 'secret' );
# build the alphabetical toc
my $toc = "\n\n" . join( ' ', a .. z ) . " \n";
# Perform LDAP queries, build directory pages
my $base = 'OU=People,OU=staff,DC=ad,DC=wjgilmore,DC=com';
for my $letter ( a .. z ) {
# Filter on the staff membership and
# first letter of samaccountname attribute
my $filter = "(&(memberof=CN=staff,OU=groups,DC=ad,DC=wjgilmore,DC=com)(samaccountname=$letter*))";
# Which attributes should be returned?
my $attrs = "sn, givenname, mail";
# Execute the search
my $results = $ad->search( base => $base, filter => $filter, attrs => $attrs );
# Check for errors!
$results->code && die $results->error;
# Build the directory
my $directory;
for my $entry ( $results->entries ) {
$directory .= sprintf '%s %s (%s)%s', $entry->get_value('givenname'), $entry->get_value('sn'),
$entry->get_value('mail'), "\n";
}
# Write the file
open( FILE, '>', "/www/wjgilmore/directory/$letter.html" );
say FILE $toc, $directory;
close FILE;
}
# Unbind from the server
$ad->unbind;