In article 
<[email protected]>,
 [email protected] (ashwin ts) wrote:

> Hi,
> 
> I am a newbie to perl.
> I have an array which has few elements like '1,2,3,4,2,3,1,2,1,1,1,4,6,7'
> i need to know how many times each element has occurred in the same array.
> for example 1-5 times
>                   2-3 times...
> could some one throw some light on how i can do this.
> thanks in advance..
> 
> Regards
> Ashwin Thayyullathil Surendran


quick write, not tested :

my @array = (1,2,3,4,2,3,1,2,1,1,1,4,6,7);
my @freq;

for (@array) { $freq[$_]++;}
  
my $i=0;
for (@freq) {
  print "$i : $_ times\n";
  $i++;
  }
  

-- 
klp

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


Reply via email to