Hello
I am fairly new at perl and I am struggling with references. I will post fictitious example underneath of what I would like to do. Hopefully someone can help me.
Intput: textfile with lines likes this:
Obi Wan "tab" Jedi "newline"
Yoda "tab" Jedi "newline"
Count Dooku "tab" Sith "newline"
...
Desired output:
A hash where the affiliations (Jedi of Sith) are the keys and the values are arrays of names (Obi Wan, Yoda, ...)
I want to create the hash while "iterating" over the file line by line.
Problem:
I got stuck with the construction of the hash.
First I checked if the key (affiliation) was defined. If not, I added the appropriate key-value pair ($hash{affiliation} => [name])
But I could not find a way to add a name to the anonymous array when the affiliation was already a key.
Many thanks in advance.
In reply to Making a hash of arrays using references by Tmms
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |