spacegeologist has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Permutation and comparison loop
by BrowserUk (Patriarch) on Apr 20, 2011 at 02:12 UTC | |
|
Re: Permutation and comparison loop
by wind (Priest) on Apr 20, 2011 at 02:46 UTC | |
by spacegeologist (Initiate) on Apr 20, 2011 at 23:14 UTC | |
by BrowserUk (Patriarch) on Apr 21, 2011 at 01:45 UTC | |
by LanX (Saint) on Apr 20, 2011 at 23:31 UTC | |
by wind (Priest) on Apr 21, 2011 at 09:09 UTC | |
by BrowserUk (Patriarch) on Apr 21, 2011 at 09:43 UTC | |
by wind (Priest) on Apr 21, 2011 at 14:05 UTC | |
|