Beefy Boxes and Bandwidth Generously Provided by pair Networks
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 arrays

by Laurent_R (Canon)
on Mar 12, 2015 at 22:56 UTC ( [id://1119891]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Struggling with complex data structures and doing useful operations on their elements and populating from arrays
in thread Struggling with complex data structures and doing useful operations on their elements and populating from arrays

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:
$a="Mary":"Owens":"cat":"white"; $b="Bill":"Thompson":"cat,dog":"white,black"; $c="Bill":"Thompson":"hamster,cat":"black,brown"; $d="Bill":"Smith":"goldfish,dog,turtle":"yellow,spotted,green";
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:

$d="Bill":"Smith":"goldfish,yellow":"dog,spotted":"turtle,green";
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.
  • Comment on Re^4: Struggling with complex data structures and doing useful operations on their elements and populating from arrays
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1119891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found