I would tend to use the second option. I think explicitly passing in args, having as few globals as possible, and having to write fewer subroutines would be a good thing. But its not the only options. You could go OO and hide all the parameters in, e.g. a hashref and just call the subs as methods, like
$dir_server->modify_directory. Or you could use closures to write the subs with some fixed parameters for each directory server, and leave the rest as args to pass in.
Looking at the docs, the new() method is the only one that returns undef and
returns an error message in $@; for the rest, you have
to examine the returned Message object. An OO example:
package DirServer;
sub new {
my $class = shift;
my ($dir, $dir_manager, $pass) = @_;
my $ldap = Net::LDAP->new($dir) or die "Couldn't connect: $@\n";
my $result = $ldap->bind($dir_manager, password=>$pass);
$result->code && die "Couldn't bind".$result->error;
bless \$ldap, $class;
}
sub modify_directory{
my $ldap = ${shift()};
my ($action_to_be_taken, $entry_to_be_adjusted,
$attribute_to_be_adjusted, $value_to_adjust_with) = @_;
my $result = $ldap -> modify($entry_to_be_adjusted,
$action_to_be_taken =>
{$attribute_to_be_adjusted => $entry_to_be_adjusted});
$result->code && die "Ya screwed up".$result->error;
}
# Then...
package main;
my $dir_server = DirServer->new(@args);
$dir_server->modify_directory(@more_args);