Hi Monks!
I am a new programmer and need help with a project I am working on.
I have two data files formatted as follows:
Station.CSV
Station,Code 1,10 2,11 3,12 4,13 5,14
and..
Parameters.CSV
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
Both of the CSV files listed above are dummy datasets, where the actual files i'm trying to use are 1,900(Station) and 48,000(Parameters) lines long.
My objective is to match station from station.csv to station in Parameters.csv and then use Code from station.csv to match the correct temperature and salinity column from Parameters.csv and return those values to station.csv. For example, in line 1 of station.csv I need it to match station 1 in Parameters.CSV and return values for S_10 and T_10 in that row. Does this make sense? Is this possible in Perl?
This is the script I have written up to this point. I am at a complete loss on how to continue.
my @Station = qw(); my @Code = qw(); open(TEXT,"<Station.csv") or die "\n\n\nFile Not Found!\n\n\n"; my @SCAL = <TEXT>; close(TEXT); foreach my $line (@SCAL) { my @dataA = split(',', $line); push (@Code, $dataA[1]."\n"); push (@Station, $dataA[0]."\n"); } open(FILE,"<Parameters.csv") or die "\n\n\nFile Not Found!\n\n\n"; my @FVCO = <FILE>; close (FILE); foreach my $lineB(@FVCO) { my @dataB = split(',', $lineB); if ( $dataB[0] == $Station[0 .. 5]) { #match correct column for salinity and salinity based off the +value for "code" } }
Please help me if you can!
In reply to Matching Values in an Array by Digs27
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |