The stupid question is the question not asked | |
PerlMonks |
Re^4: Struggling with complex data structures and doing useful operations on their elements and populating from arraysby Laurent_R (Canon) |
on Mar 12, 2015 at 22:56 UTC ( [id://1119891]=note: print w/replies, xml ) | Need Help?? |
I definitely agree that this data structure suggested by hotpelmen is most probably more appropriate to the problem description and I think that the OP should go for something along these lines. The problem, though, is that the input data is rather badly structured:
Mary Owens, no problem. Bill Smith, we can guess that the goldfish is yellow, the dog spotted and the turtle green. But this is not very robust a data structure, and it would be much better if the input data had a clear relationship between the pets and the colors. For example something like that: For Bill Thompson, we have the added difficulty that he has really a lot of pets and that they are described in two distinct lines, but that should not be too difficult to handle. My question to the hiyall: can you have a better structure, such as the one outlined just above or something similar, in your input data, or is your input data in a format that is outside your control? If you can change your input data, make it more robust. If it is not possible to change the input format, then it is not terribly complicated to still arrive to the final data structure suggested by hotpelmen, just a bit more tedious and error-prone. But my main point is that the input format is not very robust: what should your code do if you have three pets and four colors, or the other way around? The input data should presumably come from a source that is better organized, in which there is a direct relationship between the pet and the color. So it would be much better IMHO to have clear pet/color pairs in the input data. Also, if you want to change your application and allow for two colors for a pet (say a black and white dog), the change would be much easier to handle (just replace the color by a list of colors, the surrounding data structure does not need to be changed).
Je suis Charlie.
In Section
Seekers of Perl Wisdom
|
|