Hi

I'm a Perl newbie with the following task: I need to take a very long string and parse the elements of that string. The string will contains multiple occurrences of:

Dog: Beagle

Food: Type 3

Dog: Retriever

Food: table scraps

The string will have a bunch of unneeded text before and after these multiple occurences. After I parse the elements, I want to put them into a data structure. I want to group each 'Dog' - value together, and each 'Food' - value together. I also want to group each 'dog/food' pair together. I will retrieve the this information later based on the Dog value.

I think I want to use a hash of hashes. I've been reading the appropriate parts of 'Programming Perl' (which is great), but I would appreciate a nudge in the right direction, as none of the examples matches my case closely enough for me to see a solution.

Thanks!

tl


In reply to Creating data structure from multiple pairs of information by tlemons

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.