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%

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


In reply to Re: Comparing 2-D co-ordinates by BrowserUk
in thread Comparing 2-D co-ordinates by aging acolyte

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.