in reply to Working out frequency statistics with perl
Here's how I'd built the frequency statistics:
use POSIX qw(floor); sub build_histogram { my ($bucket_size, @items) = @_; my %result; for (@items) { my $bucket = $bucket_size * floor($_ / $bucket_size); $result{$bucket}++; } return %result; }
This sorts everything from 0 to $bucket_size (exlusively) into the first bucket labeled 0 etc. If you want it to be sorted into a bucket labeled $bucket_size instead, use ceil() instead of floor().
Anyway, it's hard to tell if your code is correct or not. Try to use Data::Dumper to check if the intermediate data structures are correct, and perhaps even do it manually for a short excerpt of the log files and compare the results.
|
|---|