kevyt has asked for the wisdom of the Perl Monks concerning the following question:
This will print the data without a sort.foreach ( CMP <INPUT> ){ print $_; } sub CMP { my($a0) = $a -> [2]; my($b0) = $b -> [2]; $b0 <=> $a0 }
The code I found on Friday was something like this but I could not get it to work:while (<INPUT>){ split ( $ip, $num1, $num2); printf "%18s %10s %10s\n", $ip, $num1, $num2 ; }
Can someone please help? I have spent 3 hours trying to do something so simple. Kev@sorted = map { $a->[2] cmp $b->[2] || $a->[2] <=> $b->[2] chomp; [split] <INPUT>}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting and array by [2]
by japhy (Canon) on Sep 23, 2002 at 14:30 UTC | |
|
Re: sorting and array by [2]
by kabel (Chaplain) on Sep 23, 2002 at 14:15 UTC | |
|
Re: sorting and array by [2]
by fruiture (Curate) on Sep 23, 2002 at 14:29 UTC | |
|
Re: sorting and array by [2]
by kevyt (Scribe) on Sep 23, 2002 at 15:17 UTC | |
|
Re: sorting and array by [2]
by admiraln (Acolyte) on Sep 23, 2002 at 14:57 UTC | |
|
Re: sorting and array by [2]
by kevyt (Scribe) on Sep 23, 2002 at 14:24 UTC | |
|
Re: sorting and array by [2]
by kevyt (Scribe) on Sep 23, 2002 at 15:02 UTC |