I don't quite understand what you mean by "coloured portions of a string"? What color would a peice of the string be if a red range wholey contained a yellow portion? Does the yellow become red or does the red range get split into two red ranges either side of the yellow range?

Anyway, assuming that the ranges are held in a AoA, this version should work pretty quickly and is really simple.

#! perl -slw use strict; use Data::Dumper; my @ranges = ( [17,19], [34,39], [26,29], [53,57], [43,47], [58,59] , [40,45], [30,33], [20,24], [10,15], [6,9], [1,4], , [35,45], [7, 15], ); #! initialise a string of null as long as the string the ranges perta +in to. my $coal = "\0" x 100; #! fill all the ranges with 1's substr($coal, $_->[0], $_->[1] - $_->[0] + 1) = 1 x ($_->[1] - $_->[0] + + 1) for @ranges; #print $coal; #! Build the new AoA of ranges by scanning the string recording starts + and length of string of 1's my (@new, $start); for (0 .. length $coal) { my $c = substr($coal, $_, 1); next if not $start and $c ne '1'; $start = $_ if $c eq '1' and not $start; next if $start and $c eq '1'; push @new, [$start, $_-1]; $start = undef; } print Dumper \@new; __END__ $VAR1 = [ [ 1, '4' ], [ 6, '15' ], [ 17, '24' ], [ 26, '47' ], [ 53, '59' ] ];

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.


In reply to Re: Overlapping portions of sub strings by BrowserUk
in thread Overlapping portions of sub strings by Anonymous Monk

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.