I'm not entirely sure what sort order you're expecting there. You're not sorting the timestamps; you're also not sorting the data, merely the keys for each piece of data, so that the keys will always appear in lexicographical order. For instance, if for each chunk of data and each timestamp, your hash contained values for e.g. IP, REFERER and URL, you'd always get them in that order.

I take it you'd like to sort by timestamp? Simply add a sort in foreach $date ( keys %{ $data{$cat} }) {, like so (I've also taken the liberty of adding my declarations so the script will compile under use strict, and removing the HTML bits so that the output's easier to read):

#!/usr/bin/perl use feature qw/say/; use warnings; use strict; my %data = ( 1 => { "1405799856" => { IP => "79.223.46.211" }, "1405879428" => { IP => "79.200.95.44" }, "1405702121" => { IP => "87.149.76.154" }, "1407101135" => { IP => "188.138.41.140" }, "1406108233" => { IP => "82.139.192.95" }, "1407162997" => { IP => "87.149.66.39" }, "1405810508" => { IP => "80.187.110.214" }, "1405791762" => { IP => "84.159.197.17" }, "1405870826" => { IP => "2.246.106.240" }, "1406040423" => { IP => "87.154.119.73" }, "1405810525" => { IP => "85.22.101.198" }, "1405620262" => { IP => "87.149.72.59" }, "1405603261" => { IP => "178.12.215.30" }, "1405806556" => { IP => "80.187.102.26" }, } ); foreach my $cat ( keys %data ) { foreach my $date ( sort keys %{ $data{$cat} }) { foreach my $data_type (sort { $a cmp $b } keys %{ $data{$cat}{ +$date} }) { say "$date\t$data{$cat}{$date}{$data_type}"; } } }

EDIT: added a few characters that didn't copy'n'paste, thanks redbull2012.


In reply to Re: sort on hash / hash / hash doesn't work by AppleFritter
in thread sort on hash / hash / hash doesn't work by PsySkeletor

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.