> Hello, > > I have created a multi-referenced hash /array doing the following: > > my $total; > my $machine; > my $serverdata; > > start of loop .... > > $serverdata->{$machine}->{day} = $total; > $serverdata->{$machine}->{hour} = $total / 24; > > ...end of loop > > I have a loop that gets the data for each machine and stores it. > > Now I want to print out the data but I would like to have it sorted by > the value in day. > > How would I go about doing this ? > > I was doing something like: > foreach my $key (sort %hash{$a} <=> $hash{$b} (keys (%hash))) { > blah blah blah > } >
You have it almost perfect. Assuming $serverdata looks something like my $serverdata = { machine1 => { hour => 10 , day => 240 }, machine2 => { hour => 7, day => 7 * 24 } , machine3 => { hour => 13 , day => 13 * 24 } , machine4 => { hour => 9 , day => 9 * 24 } } ; foreach my $key (sort { $serverdata->{$a}{hour} <=> $serverdata->{$b}{hour} } keys %$serverdata) { ... do something with $serverdata->{$key} ... } > > Thanks > De nada. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g Computer software consists of only two components: ones and zeros, in roughly equal proportions. All that is required is to sort them into the correct order. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>