in reply to Re^2: Top n Unique count from Array
in thread Top n Unique count from Array
I want to acheive similar output but from array.The question was why do you want an array?Why?
I want to use the IP address multiple time for various purpose in my script so I am pushing them in an array.
Tried this, following an example but output is not as I want it. Output is not sorted and where do I specify that I only want top n unique values.
But why did you try that?
Why should that code produce something sorted?
What series of steps does the code perform to produce a sorted array of IPs and hits?
Also, what do you mean where?
Please think about it, and try to answer these questions out loud ; speak the answer to your monitor or an object on your desk.
What I would do is redirect the output of the first program to a file, then execute head --lines=N file to get the top N results
ormy %Uniq; while( my $Ip = NextIp() ){ $Uniq{$Ip}++ } my @TopDown = sort { $Fun{$b} <=> $Fun{$a} } keys %Uniq; my @TopTen = @TopDown[0..9]; # @TopTen = ( sort { $Fun{$b} <=> $Fun{$a} } keys %Uniq )[ 0 .. 9];
my @Top = sort { $b->[1] <=> $a->[1] } map { [ $_, $Uniq{$_} ] } keys +%Uniq; undef %Uniq; @Top = @Top[0..9];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Top n Unique count from Array
by cipher (Acolyte) on Mar 25, 2011 at 10:26 UTC | |
by Anonymous Monk on Mar 25, 2011 at 11:36 UTC | |
by cipher (Acolyte) on Mar 27, 2011 at 06:15 UTC |