I have a hash table generated which I am then trying to add to a larger hash table, (if unique) for each of multiple files but I’m having trouble with the syntax and keep accidentally calling values or creating a hash of hash. All I want to do is turn:
(The actual $hash key) => $hash{$key};
into
$compound_hash{$key} = $hash{$key};
Currently I have:
if ($file_no == 0){
while (my ($key, $value) = each %hash){
$compound_hash{$key} = $value;
}
}else{
while (my ($key, $value) = each %compound_hash){
if (exists $hash{$key}){
print "$key: exists\n";
$compound_hash{$key} .= ",$hash{$key}";
}else{
print "$key added\n";
XXXXXXX
}
The end result is to concatenate the hash value on to the end of each line, making a .csv ie
abc,0,32,45
def,21,43,23
ghi,1,49,54
Its hard to tell exactly, but I think what you are looking for is something like this:
In my own code, I might setup
%compound_hashto be initially populated with array references, which are then joined down to strings once the data is filled.and then later
Which will be more efficient than repeatedly appending data to the strings contained in the compound hash.