much more efficient would be to divide the coordinates length by the bin side and round that off and concatenate those together and they form a pretty good hash key(and you don't need to compute minimum or maximum any more). but here's a solution following your line of thought:
use strict; use warnings; use List::AllUtils qw/minmax/; my @points = ( [3.70722,0.54617,], [3.67342,0.64892,], [3.75017,0.85075,], [3.82831,0.83506,], [3.71852,0.79251,], [3.80706,0.70426,], [3.91839,0.94094,], [3.90726,0.81722,], [3.89007,0.76107,], [3.98006,0.62477,], ); my $bins; my $binside = 0.1; my ($xmin,$xmax) = minmax( map { $_->[0] } @points ); my ($ymin,$ymax) = minmax( map { $_->[1] } @points ); for( my $xbin=$xmin ; $xbin<=$xmax ; $xbin+= $binside) { for(my $ybin=$ymin ; $ybin<=$ymax ; $ybin+= $binside) { my $p = $points[0]; if( $p->[0] >= $xbin && $p->[0] < $xbin + $binside && $p->[1] >= $ybin && $p->[1] < $ybin + $binside ) { $bins->{$xbin.$ybin} = [] unless($bins->{$xbin.$ybin}); push @{ $bins->{$xbin.$ybin} } , (shift @points); }; } } print scalar(keys(%$bins)); 4
this sounds a lot like the bin packing problem.

In reply to Re: 2D binning by spx2
in thread 2D binning by austinby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.