Oops, I was not logged in when I posted this earlier.
I have input in the following format "xx.xx.xx.xx 6 1
(ip number1 number2) and I cannot determine how to sort to sort it desending by the 3rd element. I found some code on Friday that almost worked but now I cant find it on perlmonks today.
I have tried this but it does not print $a->
2 when I try to print the values:
foreach ( CMP <INPUT> ){
print $_;
}
sub CMP {
my($a0) = $a -> [2];
my($b0) = $b -> [2];
$b0 <=> $a0
}
This will print the data without a sort.
while (<INPUT>){
split ( $ip, $num1, $num2);
printf "%18s %10s %10s\n", $ip, $num1, $num2 ;
}
The code I found on Friday was something like this but I could not get it to work:
@sorted = map { $a->[2] cmp $b->[2]
|| $a->[2] <=> $b->[2]
chomp; [split]
<INPUT>}
Can someone please help? I have spent 3 hours trying to do something so simple. Kev
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.