I am attempting to write a code that finds all overlapping images from a list of images and their maximum and minimum latitudes and longitudes.

The Input file looks like this:

"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

Here is the code, which is likely inefficient and riddled with errors, (this is my first programming language). Right now I'm just trying to compare the minimum latitudes. I've removed some warnings and comments

#Permutation loop my @n; my $n = 1; my %Image_info; ## Sort the data into a new hash. while (<>) { split /,/; $Image_info{$_[0]} = { latmin => $_[1], latmax => $_[2], lonmin => $_[3], lonmax => $_[4], }; }; ## Redifine the hash elements as scalars and begin comparison loop. for (keys %Image_info) { my $latmin1 = $Image_info{$_} -> {latmin}; my $latmax1 = $Image_info{$_} -> {latmax}; while ($n < 11) { my $latmin2 = $Image_info{$n} -> {latmin}; my $latmax2 = $Image_info{$n} -> {latmax}; if ($latmin1 > $latmin2) { print $latmin2, " is less than ", $latmin1, ".\n"; }; $n = $n +1; }; }

This is the output:

Use of implicit split to @_ is deprecated at overlap.plx line 19.

0 is less than 70.

10 is less than 70.

40 is less than 70.

The output is close but it should also print 0 is less than 10 and 10 is less than 40 ect. Can anyone tell me how to code this more effectively? Thanks in advance.


In reply to 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.