I am a much better Python programmer and have the following data structure that classifies failing tests by their overall error, which could be something like "Vehicle packet not transferred"; and a more specific error type which could be something like "Ariel Atom sent but not received".


To categorize these tests I prototyped using the following type of nested list within dict within dict Python data structure:
In [1]: data = [ row.split() for row in '''\ ...: test1 ERROR1 ERROR1:TYPE1 ...: test2 ERROR1 ERROR1:TYPE2 ...: test3 ERROR2 ERROR2:TYPE1 ...: test4 ERROR1 ERROR1:TYPE1 ...: test5 ERROR2 ERROR2:TYPE1 ...: test6 ERROR2 ERROR2:TYPE2'''.split('\n')] In [2]: data Out[2]: [['test1', 'ERROR1', 'ERROR1:TYPE1'], ['test2', 'ERROR1', 'ERROR1:TYPE2'], ['test3', 'ERROR2', 'ERROR2:TYPE1'], ['test4', 'ERROR1', 'ERROR1:TYPE1'], ['test5', 'ERROR2', 'ERROR2:TYPE1'], ['test6', 'ERROR2', 'ERROR2:TYPE2']] In [3]: nested = {} In [4]: for file, error, errortype in data: ...: nested.setdefault(error, {}).setdefault(errortype, []).app +end(file) ...: In [5]: nested Out[5]: {'ERROR1': {'ERROR1:TYPE1': ['test1', 'test4'], 'ERROR1:TYPE2': ['test +2']}, 'ERROR2': {'ERROR2:TYPE1': ['test3', 'test5'], 'ERROR2:TYPE2': ['test +6']}} In [6]: for error, errortypes in sorted(nested.items()): ...: print('\n##', error) ...: for errort, tests in sorted(errortypes.items()): ...: print('#', errort) ...: print(', '.join(tests)) ...: ## ERROR1 # ERROR1:TYPE1 test1, test4 # ERROR1:TYPE2 test2 ## ERROR2 # ERROR2:TYPE1 test3, test5 # ERROR2:TYPE2 test6 In [7]:
[download]
Could someone convert this to Perl for me so that I can learn how to manipulate this type of data structure in Perl? I have read some of the tutorials on lists within hashes but it was new to me and I don't think I'm ready to try and extend them to handle another outer level of hash. Thanks in advance- Paddy.

In reply to List in hash in hash example from Python original by paddy3118

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.