Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Hash of Arrays Sorting Problem

by kabel (Chaplain)
on Oct 29, 2002 at 20:22 UTC ( #208861=note: print w/replies, xml ) Need Help??

in reply to Hash of Arrays Sorting Problem

perhaps this gets you started:
use strict; use warnings; my %hash = ( sorter1 => { domain1 => [ 123, 124, 112, 110, ], }, ); foreach my $sorter (keys %hash) { print "\n\nSORTER=$sorter"; foreach my $domain (keys %{$hash{$sorter}}) { my $current = 0; my $show_max = 2; foreach my $time (reverse sort @{$hash{$sorter}{$domain}}) { print "\nDomain=$domain, Time=$time"; (++ $current >= $show_max) and last; } } }

always use strict and warnings. you can dump arbitrary data structures with the Data::Dumper module.
use Data::Dumper; print Dumper \%hash;

Replies are listed 'Best First'.
Re: Re: Hash of Arrays Sorting Problem
by Anonymous Monk on Oct 29, 2002 at 20:50 UTC
    The problem I run into with this approach is the times are sorted by domain. When the domain changes, the time sorting starts all over again. In other words, output could be as follows:

    Sorter=John.Doe, Time=1000, Time=1001, Time=1003, Time=1002, Time=1003

    I need all domains sorted according to ascending time
      sorry, i had an incorrect understanding about your question.
      done better below.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://208861]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2018-06-20 15:59 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.