You might find this a bit simpler:

#! perl -slw use strict; use enum qw[ IMAGENO MINLAT MAXLAT MINLON MAXLON ]; sub overlapLat { my( $a, $b ) = @_; return if $a->[MINLAT] > $b->[MAXLAT] or $a->[MAXLAT] < $b->[MINLAT]; return 1; } sub overlapLon { my( $a, $b ) = @_; return if $a->[MINLON] > $b->[MAXLON] or $a->[MAXLON] < $b->[MINLON]; return 1; } ##discard header <DATA>; my @rects = map[ split ',' ], <DATA>; my $m = 0; for my $first ( 0 .. $#rects ) { for my $second ( $first + 1 .. $#rects ) { if( overlapLat( @rects[ $first, $second ] ) and overlapLon( @rects[ $first, $second ] ) ) { print "@{$rects[ $first ] } overlaps \n@{ $rects[ $second +] }"; } } } __DATA__ "Image number","minlat","maxlat","minlon","maxlon" 1,0,30,20,50 2,10,30,70,90 3,70,80,40,50 4,40,70,20,50 5,20,75,40,80

Output:

C:\test>junk87 1 0 30 20 50 overlaps 5 20 75 40 80 2 10 30 70 90 overlaps 5 20 75 40 80 3 70 80 40 50 overlaps 4 40 70 20 50 3 70 80 40 50 overlaps 5 20 75 40 80 4 40 70 20 50 overlaps 5 20 75 40 80

One thing to watch for is whether to consider an image that ends at 70, overlaps with another that starts at 70 as with 3 & 4 above?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Permutation and comparison loop by BrowserUk
in thread Permutation and comparison loop by spacegeologist

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.