in reply to Top n Unique count from Array

I want to acheive similar output but from array.

Why?

Where is your attempt?

Replies are listed 'Best First'.
Re^2: Top n Unique count from Array
by cipher (Acolyte) on Mar 25, 2011 at 07:52 UTC
    Why?
    I want to use the IP address multiple time for various purpose in my script so I am pushing them in an array.

    Where is your attempt?
    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.
    %seen = (); foreach $item (@srcs) { push(@uniq, $item) unless $see +n{$item}++; } print "@uniq\n";

    This one only gives the unique ip addresses and not count.
    my %count; foreach $1 ( @srcs ) { $count{$1}++; } my @srcs = sort keys %count;
      I want to acheive similar output but from 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.

      The question was why do you want 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

        Dear Anonymous Monk, I am not a programmer, I have very basic perl knowledge. I am learning perl by following tutorials online and continue to do so. This is the first time I am working on hash and was hoping someone to explain me in a better way. I already posted what I tried, but you keep on asking me the answer for my question. I know my code is not good but it works, I just wanted some simple explanation of this.