in reply to Re: extract number of times a value appears in an array
in thread extract number of times a value appears in an array
The count part of the problem I'd solve thus:
use strict; use warnings; my @events_aray = (1, 3, 3, 4, 5, 5); my %days; ++$days{$_} for @events_aray; print "date $_ appeared $days{$_} times\n" for sort {$a <=> $b} keys %days;
Prints:
date 1 appeared 1 times date 3 appeared 2 times date 4 appeared 1 times date 5 appeared 2 times
You may need a different sort if your values are not numbers.
|
|---|