What you probably want is just:while (<RESULT>){ @my_data=<RESULT>; print "@my_data\n" }
otherwise you will be discarding the first line of the RESULT file. If you really want to discard the first line of the RESULT file, I would use perhaps:@my_data = <RESULT>;
<RESULT>; # reads a line from RESULT @my_data = <RESULT>; # reads rest into @my_data
Secondly, I wouldn't use my @cells = split /\"/, $_; to parse the DATA file. It looks like the data is either tab or whitespace delimited with some fields being enclosed in double quotes. I would see if Text::CSV can parse the data since it already has support for de-quoting fields. Otherwise, if no whitespace occurs within double quotes, something like this may work:
Finally, the general approach I would use to combine the files is to read one of the files into hash - the key of the hash will the field or combination of fields that are common to both files. Then when you process the other file, you can look up the corresponding data in the hash based on the values you parsed for the common fields.while (<DATA>) { chomp; my @cells = split(' ', $_); for (@cells) { s/^"(.*)"$/$1/ } ... }
I can't figure out exactly which fields you need to join on, so here's a contrived example which demonstrates the approach:
Let's suppose you have two files containing the following data:
And you want to combine the two files based on the field they have in common (the name of the state.) You first read in one of the files into a hash:File A: ALABAMA AL ALASKA AK ARIZONA AZ ARKANSAS AR CALIFORNIA CA COLORADO CO ... File B: Alabama Montgomery Alaska Juneau Arizona Phoenix Arkansas Little Rock California Sacramento Colorado Denver Connecticut Hartford Delaware Dover Florida Tallahassee Georgia Atlanta ...
Then you process the second file:my %data; open(A, '<', 'fileA'); while (<A>) { chomp; my @cells = split(' ', $_); $data{lc($cells[0])} = [ @cells ]; } close(A);
This results in something like:open(B, '<', 'fileB'); while (<B>) { chomp; my @cells = split(' ', $_); # $cells[0] is the state name, $cells[1] is the capital my $data_from_a = $data{lc($cells[0]} || []; print join("\t", @cells, @$data_from_a), "\n"; }
This will work even if the files are not alphabetized by state name.Alabama Montgomery ALABAMA AL Alaska Juneau ALASKA AK Arizona Phoenix ARIZONA AZ Arkansas Little Rock ARKANSAS AR California Sacramento CALIFORNIA CA Colorado Denver COLORADO CO ...
In reply to Re: Combine files, while parsing info.
by pc88mxer
in thread Combine files, while parsing info.
by BioNrd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |