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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: grouping numbers
by QM (Parson) on Jul 11, 2013 at 14:31 UTC | |
|
Re: grouping numbers
by ww (Archbishop) on Jul 11, 2013 at 12:44 UTC | |
by ag4ve (Monk) on Jul 11, 2013 at 13:03 UTC | |
by mtmcc (Hermit) on Jul 11, 2013 at 13:30 UTC | |
by ag4ve (Monk) on Jul 11, 2013 at 13:47 UTC | |
by mtmcc (Hermit) on Jul 11, 2013 at 14:04 UTC | |
| |
by poj (Abbot) on Jul 11, 2013 at 15:11 UTC | |
|
Re: grouping numbers
by 5mi11er (Deacon) on Jul 11, 2013 at 12:18 UTC | |
by ag4ve (Monk) on Jul 11, 2013 at 12:31 UTC | |
|
Re: grouping numbers
by mtmcc (Hermit) on Jul 11, 2013 at 12:27 UTC |