i want to count the no of variables that are same in an array please help me out
Counting Duplicate Array Elements
Collapse
X
-
Tags: None
-
one way to do it:
next time please post the code you have been working with, it might have been very close to working or not, but at least it shows effort on your part to solve the problem. ;)Code:my @array = qw(foo bar foo bar baz foo baz bar foo); my %counts = (); for (@array) { $counts{$_}++; } foreach my $keys (keys %counts) { print "$keys = $counts{$keys}\n"; }
Comment