Doesn't look too complicated. Modify to your needs:

use 5.16.2; use warnings; use Data::Peek; use Text::CSV_XS qw( csv ); my $extra = csv (in => \<<"EOC", headers => "auto"); LocnID,Lat,Lon,TestCo#,LastVol,LocnName,LocnAdr 291061000,5140598,645573,205,3568,Evans Marcross, 250401500,5141451,647444,205,857,Thomas And Ptns Somerset, 250400800,5147664,656137,205,1727,Thomas J Newton House, EOC my $base = csv (in => \<<"EOC", key => "Seq#"); 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,5140596,645572 175,0,250401500,133,141130,110343,110858,760,0,255102140,255102140,500 +5,2,505,3.0,3.2,00,00,00,141130,5141449,647452 176,0,250400800,29,141130,115529,120130,1695,0,255119079,255119079,500 +5,2,505,3.7,4.2,00,00,00,141130,5147668,656139 EOC foreach my $seq (sort keys %$base) { my @extra = grep { abs ($_->{Lat} - $base->{$seq}{GPSlat}) < 10 & +& abs ($_->{Lon} - $base->{$seq}{GPSlon}) < 10 } + @$extra; @extra > 1 and warn "Multiple matches!\n"; my $ref = $extra[0] // { Lat => 0, Lon => 0, LocnName => "?" }; printf "%5d %10d %10d %10d %10d %s\n", $seq, $base->{$seq}{GPSlat}, $base->{$seq}{GPSlon}, $ref->{Lat}, $ref->{Lon}, $ref->{LocnName}; } => 174 5140596 645572 5140598 645573 Evans Marcross 175 5141449 647452 5141451 647444 Thomas And Ptns Some +rset 176 5147668 656139 5147664 656137 Thomas J Newton Hou +se

Of course you can write a sub that finds the closest match and return the extra information. You could also hang that sub on a callback for on_in in the csv (on_in => \&foo), but that is completely up to you.


Enjoy, Have FUN! H.Merijn

In reply to Re: CSV Cross Referencing by Tux
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.