in reply to Re^3: How to code this?
in thread How to code this?
Thank you. With a few tweaks to deal with stuff not mentioned in the question, this is my addaption of your code:
our $INT //= 4; my %hash; push @{ $hash{ calcScore( $_ ) } }, $_ while <>; my @grpKeys = sort{ $a <=> $b } keys %hash; my @oldGrp; while( my $next = shift @grpKeys ) { ## Remove any arrays from teh previously processed group ## that are below the interval of the next value - $INT shift @oldGrp while ( $next - $oldGrp[ 0 ] ) > $INT. ## Process items in the new array for my $i ( 0 .. $#{ $hash{ $next } } ) { ## against each of the (other) items in the new array for my $j ( $i+1 .. $#{ $hash{ $next } } ) { process( $i, $j ); } ## and all of the items in each of the arrays ## retained from the previous pass for my $g ( @oldGrp ) { for my $j ( 0 .. $#{ $hash{ $g } } ) { process( $i, $j ); } } } ## Add this array to the previously processed group push @oldGrp, $next; }
|
|---|