Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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;

Comment on Re: Hash of Arrays Sorting Problem
Select or Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2015-10-10 11:21 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (255 votes), past polls