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

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

Replies are listed 'Best First'.
Re: Re: Re: re: readibility
by suaveant (Parson) on Apr 26, 2001 at 16:35 UTC
    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).
        Well... that's just the thing... you can sort a hash by values below it, the problem is that you are still only sorting one level of keys... which doesn't help, you need to sort and return two keys... so what you actually have to do is write code that goes through and generates a list of key pairs in the proper order... it's not a sort so much as generating an array that stores the keys properly.
                        - Ant