http://www.perlmonks.org?node_id=1043700
ag4ve has asked for the wisdom of the Perl Monks concerning the following question:

I'm cross posting from beginners mailing list

Basically I want to see most active events in logs.

Technically, I don't even want a static average - if a group is 5,6,7, I'd like to see it the same as 8,10,12,14,16 but probably have the later rank higher based on $distance/$numbers. As it is, I can't even get this to work, so...

use strict; use warnings; use Data::Dumper; my $arr = [ 10, 7, 5, 10, 50, 70, 75, 72, 79, 80 ]; my $avg; foreach my $i ($#$arr) { $avg = ($i + ($avg ? $avg : $i)) / 2; } print "avg [$avg]\n"; @$arr = sort {$a <=> $b} @$arr; my $store; foreach my $i (0 .. $#$arr) { $store->[$i]{num} = $arr->[$i]; $store->[$i]{thresh} = $avg; foreach my $store_i (0 .. $#$store) { if (abs($arr->[$i] - $store->[$store_i]{num}) <= $store->[$i]{ +thresh}) { push @{$store->[$i]{group}}, $arr->[$i]; } } } print Dumper($store);