Use a hash to check for hits from the smaller data set (A in the sample) and generate a composite list:

use strict; use warnings; my @DataA = split /\n/, <<DATAA; A "Monday" B "Tuesday" C "Wednesday" D "Thursday" DATAA my @DataB = split /\n/, <<DATAB; M 252 212 "Bill" A 325 908 "Jim" C 426 907 "Mike" A 423 383 "Sally" A 993 421 "Jim" C 737 432 "Mary" DATAB my %AHits; my @merged; for (@DataA) { my ($key, $day) = split /\s+/; $AHits{$key} = $day; } for (@DataB) { my ($key, @params) = split /\s+/; next unless exists $AHits{$key}; push @merged, [$key, $AHits{$key}, @params]; } print join ("\t", @$_), "\n" for sort {$a->[0] cmp $b->[0]} @merged;

Prints:

A "Monday" 325 908 "Jim" A "Monday" 423 383 "Sally" A "Monday" 993 421 "Jim" C "Wednesday" 426 907 "Mike" C "Wednesday" 737 432 "Mary"

DWIM is Perl's answer to Gödel

In reply to Re: Data Matching Challenge by GrandFather
in thread Data Matching Challenge by expo

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.