I agree it _would_ make it more readable and I tried to put it in a sub but the sort option (8 to be precise) comes from $query-param('sortby') (CGI.pm) which, as far as I can tell by failed attempts, I cannot pass thusly: (while using sic strict)
foreach my $x (sort sortsub($query) keys %y) {...

Every line has a time on it and I have to sort a number of logs by like times of day. Data is as follows:

log1.log<br> --------<br> Time=00:00:00.001|Request=det|Category=btyjar<br> Time=00:00:00.002|Request=sdf|Category=345<br> Time=00:00:00.003|Request=fdgh|Category=cvn<br> Time=00:00:00.004|Request=cv|Category=ryui<br> log2.log<br> --------<br> Time=00:00:00.001|Request=h5|Category=56yjh<br> Time=00:00:00.002|Request=hjk|Category=dr6<br> Time=00:00:00.003|Request=qw|Category=345<br> Time=00:00:00.004|Request=thgj|Category=234<br>

ok, that's example data. then to collect the data i use:

for my $log (@logs) { if ($log =~ /\.gz$/) { eval "`gunzip $log`"; next if $@; $log = substr $log, 0, -3; } open(LOG,$log) || warn "log not opened\n"; while (<LOG>) { chomp; my @data = split /\|/; for (@data) { my($cat,$value) = split /=/; $logdata{$log}{$.}{lc($cat)} = $value; } } close LOG; }

output is in one of two forms: log by log (so i do a little "1 of 10", "previous", "next" to switch between) or Merged - all the files in one big table. both output formats need to be sortable. the log by log is easy because I am sorting at the line level but the merged table is where I got stuck.

I do have many lines and so I need to find a way to get the sort to iterate through those lines, pulling out the time and comparing it, while still at the log level to find out in which order to sort all of the lines of all of the logs.

cheers for taking the time to look at this.


In reply to re: readibility by larryk
in thread sorting hash of hashes by tevads

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.