Hi,

Thanks for the reply.

Can this impletemented in shell script alsso?


----- Original Message ----
From: Gunnar Hjalmarsson <[EMAIL PROTECTED]>
To: beginners@perl.org
Sent: Saturday, 5 April, 2008 3:01:41 PM
Subject: Re: problem with the script in counting

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/


      Explore your hobbies and interests. Go to 
http://in.promos.yahoo.com/groups/

Reply via email to