pradeep reddy wrote:
I am stuck at how to find the occurance of column values in "swi" file.
The file has following column values: 123
324
123
123
435
435
The output should be 123 is 3 times
324 is 1 time
435 is 2 times

Use a hash.

    open my $fh, '<', 'swi' or die $!;
    my %cnt;
    while (<$fh>) {
        chomp;
        $cnt{$_}++;
    }
    foreach my $val ( sort keys %cnt ) {
        print "$val is $cnt{$val} times\n";
    }

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to