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

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

Replies are listed 'Best First'.
Re: Re: Re: Re: re: readibility
by larryk (Friar) on Apr 26, 2001 at 16:48 UTC
    > 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
        I feared as much - thanks for your help.

        Larry