Here is an example that might be helpful. There is no sorting during the hash traversal, but you should be able to pick out what you need with some simple sorts here and there.
#!/usr/bin/perl use strict; my %students = (); $students{456234567} = { name => 'Bob Smith', major => 'Engineering', level => 'Graduate', classes => { COMP8769 => { teacher => 'Dr.Smith', time => 'MWF 10:00', grade => 'A' }, COMP7960 => { teacher => 'Dr.Smith', time => 'MWF 11:00', grade => 'B' }, COMP7100 => { teacher => 'Dr. Rose', time => 'MWF 1:00', grade => 'B' }, COMP7600 => { teacher => 'Dr. Gillian', time => 'MWF 9:00', grade => 'A' }}}; $students{852234567} = { name => 'Ivan Milla', major => 'Business', level => 'Undergrad', classes => { BUS4000 => { teacher => 'Dr. Rossa', time => 'M 2:00', grade => 'C' }}}; $students{123234567} = { name => 'Sergio Veara', major => 'Arts', level => 'Graduate' }; $students{987234567} = { name => 'Richard Thompson', major => 'Economics', level => 'Undergrad', classes => { ECON6900 => { teacher => 'Dr. Jones', time => 'W 9:00', grade => 'A' }}}; $students{963434567} = { name => 'Patrick Klivert', major => 'Economics', level => 'Graduate' }; $students{789234567} = { name => 'Janfranco Vialli', major => 'Engineering', level => 'Graduate', classes => { BUS4000 => { teacher => 'Dr. Rossa', time => 'M 2:00', grade => 'A' }}}; # this will display the values of the hash foreach my $key (sort keys %students) { print "\n$key\n"; foreach my $kee (keys %{ $students{$key} }) { print " $kee : "; if (ref($students{$key}{$kee}) eq 'HASH') { foreach my $kei (keys %{ $students{$key}{$kee} }) { print "\n $kei : "; foreach my $kea (keys %{ $students{$key}{$kee}{$kei} }) { print "\n $kea : $students{$key}{$kee}{$kei}{$kea}"; } } } else { print "$students{$key}{$kee}\n"; } } }

In reply to Re: Complex Data structures and sorting by Super Monkey
in thread Complex Data structures and sorting by data67

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.