#!/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;