#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; use Data::Dumper; my $loc = "location.csv"; my $trans = "transaction.csv"; my $csv = Text::CSV_XS->new(); my %locations; # error margin my $delta = 10; sub lookup_name { my ($href, $lat, $long) = @_; for my $k (keys %$href) { my ($lat2, $long2) = @{$href->{$k}}; return $k if ((abs($lat - $lat2) < $delta) && (abs($long - $lo +ng2) < $delta)); } return "Unknown"; } open my $fh, "<", $loc or die "Can't open $loc: $!\n"; # skip header line <$fh>; while (my $rec = $csv->getline($fh)) { my ($lat, $long, $name) = (@$rec)[1, 2, 5]; push @{$locations{$name}}, $lat, $long; } print Dumper( %locations ); $csv = Text::CSV_XS->new(); close($fh); open $fh, "<", $trans or die "Can't open $trans: $!\n"; # skip header line <$fh>; while (my $rec = $csv->getline($fh)) { my @fields = @$rec; my ($lat, $long) = @fields[20, 21]; my $name = lookup_name(\%locations, $lat, $long, $delta); { local $" = ", "; print "$name -> @fields\n"; } }
This assusmes you will have 2 csv files called location.csv and transaction.csv Output is:
Evans Marcross -> 174, 0, 291061000, 59, 141130, 104945, 105755, 3355, + 0, 255094551, 255094551, 5005, 2, 505, 3.0, 3.5, 00, 00, 00, 141130, + 5140596, 645572 Thomas And Ptns Somerset -> 175, 0, 250401500, 133, 141130, 110343, 11 +0858, 760, 0, 255102140, 255102140, 5005, 2, 505, 3.0, 3.2, 00, 00, 0 +0, 141130, 5141449, 647452 Thomas J Newton House -> 176, 0, 250400800, 29, 141130, 115529, 12013 +0, 1695, 0, 255119079, 255119079, 5005, 2, 505, 3.7, 4.2, 00, 00, 00, + 141130, 5147668, 656139

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