If I understand your data structure, you could do it the following way.

#!perl use strict; my %data = ( 'sort 1' => {'a.b.c' => ['19:20', '20:30'], 'a.b.d' => ['15:10', '19:40']}, 'sort 2' => {'e.f.g' => ['12:13'], 'g.h.i' => ['8:15', '23:11']}); my %times; foreach my $sorter (values %data) { foreach my $domain (keys %$sorter) { foreach my $time (@{$sorter->{$domain}}) { push(@{$times{$time}}, $domain); } } } foreach my $time (sort { cmpTime($a, $b) } keys %times) { foreach my $domain (@{$times{$time}}) { print "domain: $domain, time: $time\n"; } } sub cmpTime { my ($t1, $t2) = @_; my ($h1, $m1) = split(/:/, $t1); my ($h2, $m2) = split(/:/, $t2); return 60*$h1 + $m1 <=> 60*$h2 + $m2; }

Of course, you'd have to adapt cmpTime to reflect the format your time stamps are in.

Hope this helps, -gjb-


In reply to Re: Hash of Arrays Sorting Problem by gjb
in thread Hash of Arrays Sorting Problem by Anonymous Monk

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.