This seems to do what you want without too much thrashing around. It should cope with overlapping sets (5 or more consecutive numbers) although I haven't tested that.

use strict; use warnings; use Data::Dumper; my @a1 = ( 100, 204, 312 ); my @a2 = ( 102, 313, 409 ); my @a3 = ( 205, 206, 315 ); my @a4 = ( 207, 210, 314 ); ## Two contiguous sequences of 4 values: 204 .. 207 & 312 .. 315 my $arrayNo = -1; my @ints = sort {$a->[0] <=> $b->[0]} map { my $raOrig = $_; my @items = (); push @items, [$raOrig->[0]->[$_], qq{$raOrig->[1]:$_}] for 0 .. $#{$raOrig->[0]}; @items; } map { $arrayNo ++; [$_, $arrayNo] } \@a1, \@a2, \@a3, \@a4; my @sets; for my $window (0 .. $#ints - 3) { push @sets, [@ints[$window .. $window + 3]] if $ints[$window]->[0] == $ints[$window + 3]->[0] - 3; } print Dumper \@sets;

The Dumper output is

$VAR1 = [ [ [ 204, '0:1' ], [ 205, '2:0' ], [ 206, '2:1' ], [ 207, '3:0' ] ], [ [ 312, '0:2' ], [ 313, '1:1' ], [ 314, '3:2' ], [ 315, '2:2' ] ] ];

I hope this is of use.

Cheers,

JohnGG

Update: Removed superfluous variable $elemNo left over from development


In reply to Re: Searching parallel arrays. by johngg
in thread Searching parallel arrays. by BrowserUk

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.