Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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
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
Node Status?
node history
Node Type: note [id://208861]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-12-25 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls