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:
- 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, ],
);
- With this information you can easily find, for each starting point, where it is located.
- You will also find easily where each end point can be found.
- 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
- Implementation is left as an excercise to you ;-)
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e