in reply to placing values into bins
This is untested, but I think (hope) it gives you at least an idea of one way to do it. Of course you can make it more efficient, shorter, etc.my $range = 1; my $hash = {}; while (<>) { chomp; my ($num1, $num2) = split ' ',$_; # key the numbers my $int_num1 = int( $num1 ); # drop the decimal # this will create the correct key for an integer range # e.g. if you had a range of 5, this would result in # 120 being the first bucket my $key1 = $int_num1 - ($int_num1 % $range); # combined steps for key2 my $key2 = int($num2) - (int($num2) % $range); $hash->{$key1}->{$key2}++; } # now you can get your indices foreach my $range1 ( keys %$hash ) { foreach my $range2 ( keys %{$hash->{$range1}} ) { print $range1."-".($range1+$range); print " "; print $range2."-".($range2+$range); print " "; print $hash->{$range1}->{$range2}; print "\n"; } }
|
|---|