in reply to Re^2: How can I sort this data on the fourth field?
in thread How can I sort this data on the fourth field?
You need to build an array (with push @data, $line;) inside your while loop, between that next and the closing brace.
The sort snippet I posted should be placed after the closing brace of the while.
Something like:
my @data; while (my $line = <$fh>) { chomp($line); last if ($line =~ /TOTAL COMMAND SUMMARY/); next if (($line =~ /^[a-zA-Z]/) or ($line =~ /^\s*$/) or ($line =~ / +^\s/)); push @data, $line; } my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map [ $_, (split)[3] ], @data;
Going on the data you posted, wouldn't that next be better written as:
next unless $line =~ /^\d/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How can I sort this data on the fourth field?
by country1 (Acolyte) on Aug 16, 2007 at 14:23 UTC | |
by FunkyMonk (Bishop) on Aug 16, 2007 at 14:31 UTC |