It appears to me that each of your triple (X # Y) is a piece of a route with X being the starting point and Y being the end point.

What you seem to have in $array is a long route and a shorter one in $delim.

No you seem to want to find regions in $array that give you the same stop on the long route, you got on the short.

So here is my idea:

  1. Make two HoA where you store for each starting and each end point a list of indeces in your $array where to find them
    example data structure:
    %start = ( A => [ 0, 1, ], B => [ 4, 6, ], C => [ 2, 5, ], D => [ 3, ], } %end = { A => [ 0, ], B => [ 3, 5, ], C => [ 1, 4, ], D => [ 2, ], E => [ 6, ], );
  2. With this information you can easily find, for each starting point, where it is located.
  3. You will also find easily where each end point can be found.
  4. A valid route from A to C are now all those ranges where the value from @{$start{'A'}} is less or equal to a value from @{$end{'C'}}
    This should be:
    A C
    0 1
    0 4
    1 1
    1 4
  5. Implementation is left as an excercise to you ;-)


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

In reply to Re: Identifying Delimited Regions of an Array by Skeeve
in thread Identifying Delimited Regions of an Array by neversaint

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.