in reply to Passing 2 elements into a new associative array

All you need is one more step... Only you didn't say which value you want to use as the hash key, thus, which value you want to use to do the lookup, and thus, which must be unique. I'll just assume that you want to use $dn for that. Then, change your code to:
my %lookup; while (<$LDIF>) { my ($dn) = /^dn: (.*)$/m; my ($samACCOUNTNAME) = /^samACCOUNTNAME: (.*)$/m; $lookup{$dn} = $samACCOUNTNAME if defined $dn and defined $samACCOUNTNAME; # only if both are fou +nd }
Reverse the placement of the two variables in my additional line, if my assumption is the wrong way around.

In case you don't know what to do next: you can look up the account name by dn simply by using $lookup{$current_dn}. exists $lookup{$current_dn} may help to see if there is a value for it in this table, though with all values garanteed to be defined — due to the way I added them, you could just as well use defined instead. Or, if all valid account names are supposed to be neither "" nor "0", just test its truth value, as in

if($lookup{$current_dn}) { ... }

You want to associate more than one value with one key, you'll have to use arrays for the hash values. There is no middle ground, you either use the strings for value, or use arrays for all. Simply change my added line to:

push @{$lookup{$dn}}, $samACCOUNTNAME;
The first name would then be in
$lookup{$current_dn}[0]

Replies are listed 'Best First'.
Re^2: Passing 2 elements into a new associative array
by contrite_newbie (Novice) on Oct 07, 2004 at 04:21 UTC
    Thx, Bart...I didn't think of using %foo before the while statement in order to create the hash. I want samACCOUNTNAME as the $key/$value pairing where $value will equal the username value in the csv file...