Of course, Perl is perfectly suited for this kind of tasks!

use Modern::Perl '2014'; my @data; <DATA>; # discard header line while (<DATA>) { chomp; last if $_ eq 'END PARAMETERS'; # end of data marker, not neces +sary if reading from a file my ( $station, @fields ) = split /,/; $data[$station] = \@fields; } <DATA>; # discard header line while (<DATA>) { chomp; my ( $station, $level ) = split /,/; say "Station $station: salinity $level is $data[$station][$level-10] and t +emperature $level is $data[$station][$level-4]"; } __DATA__ Station,S_10,S_11,S_12,S_13,S_14,S_15,T_10,T_11,T_12,T_13,T_14,T_15 1,31,29,29,31,29,29,15,14,23,15,14,23 2,33,28,23,33,28,23,17,15,23,17,15,23 3,23,27,33,23,27,33,18,16,23,18,16,23 4,25,26,28,25,26,28,23,14,15,23,14,15 5,26,26,27,26,26,27,23,18,17,23,18,17 6,27,33,31,27,33,31,14,17,18,14,17,18 7,33,29,29,33,29,29,12,18,23,12,18,23 END PARAMETERS Station,Code 1,10 2,11 3,12 4,13 5,14
Output:
Station 1: salinity 10 is 31 and temperature 10 is 15 Station 2: salinity 11 is 28 and temperature 11 is 15 Station 3: salinity 12 is 33 and temperature 12 is 23 Station 4: salinity 13 is 25 and temperature 13 is 23 Station 5: salinity 14 is 26 and temperature 14 is 18

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

In reply to Re: Matching Values in an Array by CountZero
in thread Matching Values in an Array by Digs27

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.