There are many ways to do so, and the solution (of course) depends on your requirements. Based on your example, try the following approach:
- read the text-file into one string
- split the string based on your delimiter (which seems to be a blank). This will give you an array
- Pass through the array.
- check if the current element is a key (a single letter in your example, use =~ /\w/)
- if yes: check if the next element is a value
- if yes: store the value to the hash (using the key identified before)
- if no: store an empty value to the hash (using the key identified before)
- continue with the next element
Of course you can optimize. And probably you have to adapt the algorithm - but I hope it gives you an idea!
Rata