in reply to sort array by value in it
Cheers - L~R#!/usr/bin/perl use strict; use warnings; my @data; while ( <DATA> ) { next if /^host:volume/; chomp; my @field = $_ =~ /^([^:]+):([^\s]+)\s+(\d+)\s+(\d+)/; push @data, \@field; } for ( sort { $data[$a]->[2] <=> $data[$b]->[2] } 0 .. $#data ) { print join "\t" , @{ $data[$_] }; print "\n"; } __DATA__ host:volume available(MB) %free 10.100.200.1:/dev/hda3 10168 80% 10.100.200.1:/dev/hda2 84 90% 10.100.200.2:/dev/hda3 10168 80% 10.100.200.2:/dev/hda2 84 90%
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: sort array by value in it
by Anonymous Monk on May 04, 2004 at 16:08 UTC | |
by Limbic~Region (Chancellor) on May 04, 2004 at 16:13 UTC | |
by Anonymous Monk on May 04, 2004 at 16:33 UTC | |
by Limbic~Region (Chancellor) on May 04, 2004 at 16:51 UTC | |
by demerphq (Chancellor) on May 04, 2004 at 20:08 UTC | |
|