in reply to re: readibility
in thread sorting hash of hashes

Still a little confused... do you want to sort by log, then by other data? If that is the case you need to use two sorts... do an outer loop to sort by log, then an inner loop to sort by your other data using the log from the first sort...
                - Ant

Replies are listed 'Best First'.
Re: Re: re: readibility
by larryk (Friar) on Apr 26, 2001 at 15:38 UTC
    I need to sort all of the lines in all of the logs by the time on each line. so I need to sort $logdata->{log1..logN} by getting Perl's sort to compare $logdata->{$a}->{$line1..$lineN}->{'time'} to $logdata->{$b}->{$line1..$lineN}->{'time'}

    If I first sort the logs and then do an inner sort on time then I will still have segregation by log but I have to put it all together so if an event happened at 12:00:43.001 in the 3rd log, it will appear above the event at 13:34:23.843 in the 1st log, but below the event at 04:04:21.891 in the 7th log.

    larryk

      Well... then you have to decide if you want to sort by the minimum time in lines, the maximum time in lines, or the average time in lines... cuz you can't just sort by a bunch of values...

      Wait.. are you trying to sort all of the lines into a big mix of lines? so that individual lines from all the logs come out in order? If that is the case then you can't do it with a simple sort the way you have your hash of hashes set up. What you should do in that case is build a composite key... $log.$line or something similar, so then you would do...

      foreach (sort $logdata->{$a}{time} cmp $logdata->{$b}{time}) {
      See what I'm saying... because otherwise you can only sort to a granularity of the log level, or you can sort the lines in a log, but not both, without a lot more work...
                      - Ant
        > are you trying to sort all of the lines into a big mix of lines?
        Yes.

        > $log.$line or something...
        this is almost exactly what my fix was ($log.'|'.$line).

        It's the "more work" that I'm interested in. I figure there has to be a way to sort a multidimensional hash at the top level by a middle/bottom level key/value (without populating another hash with all the keys to that level joined as the new key).