I apologize for not being clear enough, but this is a Perl question. The script I am trying to modify currently runs a SELECT query with a WHERE statement multiple times within a foreach loop. I would like to run the query once and pull the necessary data from an array instead. Below is the segement of code I'm working with:
# Bind to LDAP Server
$ldap = Net::LDAP->new( $ldapServer ) or die "$@";
$bind = $ldap->bind( $ldapUser, password => $ldapPass );
# Connect to SQL Server
$connect = Mysql->connect($sqlServer, $sqlDB, $sqlUser, $sqlPass);
$ldapResult = $ldap->search(
base => $ldapBaseOU,
filter => "(&(usertype=Employee))",
attrs => @ldapAttrs
$sqlQuery = "SELECT username,email,phone FROM users";
$sqlResult = $connect->query($sqlQuery);
my @entries = $ldapResult->entries;
foreach $entry ( @entries )
my $username = $entry->get_value ( 'sAMAccountName' );
my $dn = $entry->dn;
### ***** Insert Match Here ***** ###
$phone = ??
$email = ??
# Unbind from LDAP Server
$bind = $ldap->unbind;
In the section noted as "***** Insert Match Here *****, I would like to be able to use the $username value pulled from LDAP and match it to the 'username' value pulled from MySQL to set the phone and email variables.