I have two arrays, representing start and stop positions for a sequence,
@a=(1,15,30,50,65) @b=(5,20,37,55,77)
so for example, the first elements of each array (1 and 5) represent the numbers 1,2,3,4,5; the two arrays define the numbers 1,2,3,..5,15,16,..,20,...,65,66,...,77) Now, I also have two scalars, say, $s1=9, $s2=35, where these also represent a range of integers 9,10,11,..,35. The problem is to find the numbers defined by @a and @b which intersect with the range defined by $s1 and $s2.

I tend to things the long way in perl, so I thought of creating an array of arrays

@AoA=([1,5],[15,20],...,[65,77]) <p>
then finding the intersection of ($s1..$s2) with each of the array elements.

If anybody can think of a better way to do this, any help much appreciated, otherwise, a good way to create the array of array would also be appreciated.

Thanks in advance!


In reply to array of arrays or not by coldy

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.