#!/usr/bin/perl use strict; use warnings; my $numBuckets = 20; my @points = map {{x => $_->[0], 'y' => $_->[1], dy => $_->[2]}} map {chomp; [split]} ; my @buckets; my $min = $points[0]{x}; my $max = $points[0]{x}; for my $point (@points) { $min = $point->{x} if $min > $point->{x}; $max = $point->{x} if $max < $point->{x}; } my $scale = ($max - $min) / $numBuckets; push @{$buckets[($_->{x} - $min) / $scale]}, $_ for @points; for my $bucket (@buckets) { # Sort contents of bucket by weighting function next if !defined $bucket; @$bucket = sort {$a->{dy} <=> $b->{dy}} @$bucket; } for my $index (0 .. $numBuckets - 1) { printf "%3d: ", $index; printf "%.4f, %.4f, %.4f", @{$buckets[$index][0]}{qw(x y dy)} if defined $buckets[$index]; print "\n"; }