Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Hash of Arrays Sorting Problem

by kabel (Chaplain)
on Oct 29, 2002 at 20:22 UTC ( [id://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
    Domain=domain1.com, Time=1000
    Domain=domain1.com, Time=1001
    Domain=domain1.com, Time=1003
    Domain=domain2.com, Time=1002
    Domain=domain2.com, 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://208861]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found