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.

In reply to Re^4: Struggling with complex data structures and doing useful operations on their elements and populating from arrays by Laurent_R
in thread Struggling with complex data structures and doing useful operations on their elements and populating from arrays by hiyall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.