Here is an way of doing it with a combination of Data::Table and Math::Round. As others have mentioned, there may be a better algorithm for determining a match for lat/lon coordinates based on distances. However, the method below can be adjusted using the $tol variable. Using the two data tables that you provided and $tol = 10 I get one match in the joined table, using $tol = 50 all three match.
#!/usr/bin/env perl use strict; use warnings; use Data::Table; use Math::Round; my $tol = 50; # Tolerance, i.e. round values to the neared multiple of + $tol my $t1 = Data::Table::fromCSV("data1.txt", 1, undef); # Delete lat & lon columns are replace with rounded values my $gps_lat_col = $t1->delCol("GPSlat"); my $gps_lon_col = $t1->delCol("GPSlon"); my @nGPSlat = map{ nearest($tol, $_) } @{$gps_lat_col}; my @nGPSlon = map{ nearest($tol, $_) } @{$gps_lon_col}; $t1->addCol(\@nGPSlat, "GPSlat"); $t1->addCol(\@nGPSlon, "GPSlon"); print "\nTable 1\n"; print $t1->csv; my $t2 = Data::Table::fromCSV("data2.txt", 1, undef); #, { delimiter = +> " " }); # Delete lat & lon columns are replace with rounded values my $lat_col = $t2->delCol("Lat"); # Delete column 'age'. my $lon_col = $t2->delCol("Lon"); # Delete column 'age'. my @nlat = map{ nearest($tol, $_) } @{$lat_col}; my @nlon = map{ nearest($tol, $_) } @{$lon_col}; $t2->addCol(\@nlat, "Lat"); $t2->addCol(\@nlon, "Lon"); print "\nTable 2\n"; print $t2->csv; # Join the tables for cases where the rounded lat/lon pairs are exact +matches my $t3 = $t1->join($t2, Data::Table::INNER_JOIN, [ 'GPSlat', 'GPSlon' +], ['Lat', 'Lon']); print "\nJoined Table\n"; print $t3->csv; exit;
Output:
Table 1 Seq#,TransType,LocnNum,TankNum,Date,TimeStart,TimeEnd,TktVol,AltVol,To +talSrt,TotalEnd,Driver,Trip,Route,MeanDegC,MaxDegC,ColCd,Ccode,TestTy +pe,TrpSdate,GPSlat,GPSlon 174,0,291061000,59,141130,104945,105755,3355,0,255094551,255094551,500 +5,2,505,3.0,3.5,00,00,00,141130,5140600,645550 175,0,250401500,133,141130,110343,110858,760,0,255102140,255102140,500 +5,2,505,3.0,3.2,00,00,00,141130,5141450,647450 176,0,250400800,29,141130,115529,120130,1695,0,255119079,255119079,500 +5,2,505,3.7,4.2,00,00,00,141130,5147650,656150 Table 2 LocnID,TestCo#,LastVol,LocnName,LocnAdr,Lat,Lon 291061000,205,3568,Evans Marcross,,5140600,645550 250401500,205,857,Thomas And Ptns Somerset,,5141450,647450 250400800,205,1727,Thomas J Newton House,,5147650,656150 Joined Table Seq#,TransType,LocnNum,TankNum,Date,TimeStart,TimeEnd,TktVol,AltVol,To +talSrt,TotalEnd,Driver,Trip,Route,MeanDegC,MaxDegC,ColCd,Ccode,TestTy +pe,TrpSdate,GPSlat,GPSlon,LocnID,TestCo#,LastVol,LocnName,LocnAdr 176,0,250400800,29,141130,115529,120130,1695,0,255119079,255119079,500 +5,2,505,3.7,4.2,00,00,00,141130,5147650,656150,250400800,205,1727,Tho +mas J Newton House, 175,0,250401500,133,141130,110343,110858,760,0,255102140,255102140,500 +5,2,505,3.0,3.2,00,00,00,141130,5141450,647450,250401500,205,857,Thom +as And Ptns Somerset, 174,0,291061000,59,141130,104945,105755,3355,0,255094551,255094551,500 +5,2,505,3.0,3.5,00,00,00,141130,5140600,645550,291061000,205,3568,Eva +ns Marcross,

In reply to Re: CSV Cross Referencing by kevbot
in thread CSV Cross Referencing by Jalcock501

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.