in reply to Comparing 2-D co-ordinates
You can avoid the need to sort or even do any comparisons. Just loop through the data and build a string using one character to represent your ranges and another the 'freespace'. Then just count the non-freespace chars and your done.
#! perl -slw use strict; my @data = map{ [ split "','", substr( $_, 1, -2 ) ] } <DATA>; my $mask = ' ' x 10_000; # Make a blank string that's 'big enough' my $max = 0; # we'll trim it back later for( @data ) { #calc the length of the range my $len = $_->[2] - $_->[1] +1; # overwrite the range with 'xx's substr( $mask, $_->[1], $len ) = 'x' x $len; # Remember the highest offset $max = $_->[2] if $_->[2] > $max; } $mask = substr( $mask, 0, $max ); # Trim to length my $coverage = $mask =~ tr[x][x]; # Count the 'x's printf "cover = %.1f%% \n", $coverage / length($mask) *100; __DATA__ 'NM_176827','618','710' 'NM_176827','621','710' 'NM_176827','622','692' 'NM_176827','629','710'
Output
P:\test>279587 cover = 13.0%
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Comparing 2-D co-ordinates
by Anonymous Monk on Jul 31, 2003 at 15:20 UTC | |
by aging acolyte (Pilgrim) on Jul 31, 2003 at 15:35 UTC | |
by BrowserUk (Patriarch) on Jul 31, 2003 at 16:07 UTC | |
by belg4mit (Prior) on Jul 31, 2003 at 15:47 UTC | |
|
Re: Re: Comparing 2-D co-ordinates
by aging acolyte (Pilgrim) on Jul 31, 2003 at 15:19 UTC | |
by BrowserUk (Patriarch) on Jul 31, 2003 at 15:27 UTC |