Interesting problem:^), could do with a little more sample data to go on though.
Anyway, the method I would use is to set up a 2-dimensional array of hashes of the grid data. To do this you need to map the grid x's and y's to a zero-based index (to conserve space). Unfortunately the data you supplied doesn't give me much clue on the spacing of the grid. It appears to be (approximately) 1066.66... in the x dimension and 933.33... in the y dimension. But this doesnt quite map exactly. However using this to divide the left-X and the top-Y and then substract 58 and 97 respectively should map the coordinates to 0..n indices. Then I store a hash of all the grid information..
Once the grid array has been built, it is then just a case of reading the place information one line at a time converting the coordinates in the same way and then using that to look up the required info.
However, as the mapping isn't exact, you then need to compare the real (x,y) from the place info against that stored in the mapped hash and adjust by one up or down on each axis as necessary.
That done, you have the mapped info to use as required.
Note: For obvious reasons the code below is untested, but it compiles clean and should give you a starting point.
I'd also be interested to know
#! perl -sw use strict; #! The rounding may need some correction. sub Xtoix{ int($_[0]/(1066+2/3)+.5) } #! the closest approximate mappi +ng functions sub Ytoiy{ int($_[0]/( 933+1/3)+.5) } #! I could derive from your limi +ted sample data. my @grid; open GRIDS, 'yourgridsfile' or die $!; while(<GRIDS>) { #! Isolate the data my ($map, $grid, $subgrid, $x0, $y0, $x1, $y1 ) = split ','; my $ix = Xtoix( $x0 ); #! map to 0 based indexes my $iy = Ytoiy( $y0 ); #! build and store a hash with the data into the grid. $grid[$ix][$iy] = {map=>$map, grid=>$grid, subgrid=>$subgrid, x0=>$x0, y0=>$y0, +x1=>$x1, y1=>$y1 }; } close GRIDS; open PLACES, 'yourplacefilename' or die $!; while(<PLACES>) { my ($thingy, $x, $y)= split ','; # Forgot to split!! my $ix = Xtoix( $x ); my $iy = Ytoiy( $y ); my $adjusted = 0; my $gridref = $grid[$ix][$iy]; ++$adjusted, $ix-- if $x < $gridref->{x0}; ++$adjusted, $ix++ if $x > $gridref->{x1}; ++$adjusted, $iy-- if $y < $gridref->{y0}; ++$adjusted, $iy++ if $y > $gridref->{y1}; $gridref = $grid[$ix][$iy] if $adjusted; print $thingy, ' is on map ', $gridref->{map}, ' at grid ', $gridref->{grid}, ' subgrid ', $gridref->{subgrid}, } close PLACES;
P.s. I think that this should work regardless of whether the sources files are sorted. The neat bit (from an ex-C and other languages programmer's point of view) is the autovivication of the 2-dimensional array.
In reply to Re: Search file of coordinates
by BrowserUk
in thread Search file of coordinates
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |