Depends how you want to access it more than anything else. Either a HoHoA, a HoAoA or a HoAoH would fit the bill. This is a HoHoA variant:

use strict; use warnings; my %data_sets; my @dataHeaders = split /,/, ($_ = <DATA>, chomp, $_); my @setHeaders = split /,/, ($_ = <DATA>, chomp, $_); splice @setHeaders, 2; # Assume paired columns and the same for all da +ta sets while (<DATA>) { chomp; my @fields = split /,/; Outer: for my $dataSet (@dataHeaders) { for my $field (@setHeaders) { last Outer unless @fields; push @{$data_sets{$dataSet}{$field}}, shift @fields; } } } my $lu = $data_sets{'Data Set 3'}{'X units'}[2]; # Data Set 3's x3 val +ue my @matches = grep {$data_sets{'Data Set 1'}{'X units'}[$_] eq $lu} 0 .. $#{$data_sets{'Data Set 1'}{'X units'}}; for my $index (@matches) { print "Data Set 1 element X" . ($index + 1) . "'s Y = $data_sets{'Data Set 1'}{'Y units'}[$in +dex]\n"; } __DATA__ Data Set 1,Data Set 2,Data Set 3 X units,Y units,X units,Y units,X units,Y units 1,y1,x1,y1,2,y1 2,y2,x2,y2,3,y2 3,y3,x3,y3,1,y3

Prints:

Data Set 1 element X1's Y = y1

The s/\t/,/g was to avoid unnoticed editor foibles.


DWIM is Perl's answer to Gödel

In reply to Re: Help munging tabular data by GrandFather
in thread Help munging tabular data by c4onastick

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.