in reply to Re: Re: Re: sort array by value in it
in thread sort array by value in it
#! /usr/bin/perl -w # # drivespace # use strict; use Mobile::Executive; my %space; ###################################################################### +###################################################### sub do_it { return scalar `df -Tm`; } ###################################################################### +####################################################### relocate( 'xxx.xxx.xxx.xxx', 2001 ); $space{ 'xxx.xxx.xxx.xxx' } = do_it; relocate( 'xxx.xxx.xxx.xxx', 2001 ); $space{ 'xxx.xxx.xxx.xxx'} = do_it; #relocate( 'xxx.xxx.xxx.xxx', 2001 ); #$space { 'xxx.xxx.xxx.xxx'}= do_it; #relocate( 'xxx.xxx.xxx.xxx', 2001 ); #$space = { 'xxx.xxx.xxx.xxx'}do_it; #relocate( 'xxx.xxx.xxx.xxx', 2001 ); #$space = { 'xxx.xxx.xxx.xxx'}do_it; relocate( 'xxx.xxx.xxx.xxx', 2001 ); my $counter = 1; my @out; my @lines; my $disk_used = 0; my $free = 0; print "host:volume available(MB) %free\n"; foreach my $host (keys %space) { $_ = $space{$host}; @lines = map { /(\/\w+\/\w+)\s+\w+\s+\d+\s+\d+\s+(\d+)\s+(\d+)%/; { volume => $1, available => $2, free => 100 - $3, } }split /\n/,$space{$host}; #This is the sorting line! @lines = sort { $b->{available} <=> $a->{available} } @lines; push @out, "$host:$_->{volume} $_->{available} $_->{free +}%" for @lines; }
Edited by Chady -- removed real IPs
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: sort array by value in it
by dragonchild (Archbishop) on May 04, 2004 at 15:54 UTC |