in reply to 2D binning

It's really quite hard to tell from either your description, or your code (was it translated from another language? FORTRAN?), what you are trying to do.

My best guess is that you are trying to count the number of xy pairs that fall into each 0.1 interval in both the x & y dimensions. If so, your code is working far too hard. I think this might be a simpler approach:

#! perl -slw use strict; use List::Util qw[ sum ]; use Data::Dump qw[ pp ]; our $X //= 10; our $Y //= 10; my @xs = map -3+rand 6, 1 .. $X; my @ys = map -3+rand 6, 1 .. $Y; my %bins; for my $x ( @xs ) { my $xc = ( int( $x * 10 ) + 0.5 ) / 10; for my $y ( @ys ) { my $yc = ( int( $y * 10 ) + 0.5 ) / 10; ++$bins{ "$xc:$yc" }; } } pp \%bins; printf "Buckets used: %d, total values %d \n", scalar keys %bins, sum values %bins;

Output:

c:\test>824030 -X=10 -Y=10 { "-0.15:-0.55" => 2, "-0.15:-1.25" => 1, "-0.15:-2.15" => 1, "-0.15:-2.25" => 1, "-0.15:-2.35" => 1, "-0.15:-2.45" => 1, "-0.15:-2.55" => 1, "-0.15:0.05" => 1, "-0.15:2.05" => 1, "-1.15:-0.55" => 2, "-1.15:-1.25" => 1, "-1.15:-2.15" => 1, "-1.15:-2.25" => 1, "-1.15:-2.35" => 1, "-1.15:-2.45" => 1, "-1.15:-2.55" => 1, "-1.15:0.05" => 1, "-1.15:2.05" => 1, "-1.65:-0.55" => 2, "-1.65:-1.25" => 1, "-1.65:-2.15" => 1, "-1.65:-2.25" => 1, "-1.65:-2.35" => 1, "-1.65:-2.45" => 1, "-1.65:-2.55" => 1, "-1.65:0.05" => 1, "-1.65:2.05" => 1, "-1.75:-0.55" => 4, "-1.75:-1.25" => 2, "-1.75:-2.15" => 2, "-1.75:-2.25" => 2, "-1.75:-2.35" => 2, "-1.75:-2.45" => 2, "-1.75:-2.55" => 2, "-1.75:0.05" => 2, "-1.75:2.05" => 2, "-2.55:-0.55" => 2, "-2.55:-1.25" => 1, "-2.55:-2.15" => 1, "-2.55:-2.25" => 1, "-2.55:-2.35" => 1, "-2.55:-2.45" => 1, "-2.55:-2.55" => 1, "-2.55:0.05" => 1, "-2.55:2.05" => 1, "-2.65:-0.55" => 2, "-2.65:-1.25" => 1, "-2.65:-2.15" => 1, "-2.65:-2.25" => 1, "-2.65:-2.35" => 1, "-2.65:-2.45" => 1, "-2.65:-2.55" => 1, "-2.65:0.05" => 1, "-2.65:2.05" => 1, "0.05:-0.55" => 2, "0.05:-1.25" => 1, "0.05:-2.15" => 1, "0.05:-2.25" => 1, "0.05:-2.35" => 1, "0.05:-2.45" => 1, "0.05:-2.55" => 1, "0.05:0.05" => 1, "0.05:2.05" => 1, "0.25:-0.55" => 2, "0.25:-1.25" => 1, "0.25:-2.15" => 1, "0.25:-2.25" => 1, "0.25:-2.35" => 1, "0.25:-2.45" => 1, "0.25:-2.55" => 1, "0.25:0.05" => 1, "0.25:2.05" => 1, "2.95:-0.55" => 2, "2.95:-1.25" => 1, "2.95:-2.15" => 1, "2.95:-2.25" => 1, "2.95:-2.35" => 1, "2.95:-2.45" => 1, "2.95:-2.55" => 1, "2.95:0.05" => 1, "2.95:2.05" => 1, } Buckets used: 81, total values 100

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"