Avatar of melon

asked on 

Sorting hash of a hash

I have a script to parse logfiles with fields these fields: servername, freepercentage space, date

I have provided just a snippet of the code below. The program prints out a table to HTML with each server in the first column and the corresponding free space for the $lastday in the next column. I would like to print out the list sorting by the free space $percs{$server}{$_} for $lastday in descending order.
foreach $logfile (glob($dir_of_logs))
while (<LOG>)
        my ($server, $freepercentage, $date)  = split /,/;
# Get days in chronological order
@days_order = map{$_->[0]} sort {$a->[1] cmp $b->[1]} map{[$_, sprintf("%02d%02d%02d",(split(/\//, $_))[2,0,1])]}keys %days;
$lastday = $days_order[-1];
foreach $server (sort keys %percs)
print $server;
for ($lastday)
        $lastperc = (sprintf "%.2f", $percs{$server}{$_});
print $lastperc;

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon