Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
i need to merge the data in file 2 to the relevant rows in file 1 based on the complex number. However, the order in file 2 is not the same as file 1. Thought hash would be useful to lookup the complex numbers. I can merge the data but how can i incorporate the values in file 1 also?FILE 1 complex.1 1.356 complex.2 1.879 etc file 2 12.02 /home/complex.2out 10.25 /home/complex.1out etc
myoutput is$string = 'complex'; open(REF, "<file1"); chomp; my %pd_file = map { /^(\S+)\s+(\S+).*/; } <REF>; close(REF); open (ET, "<file2"); while (<ET>) { chomp; /^(\S+\s+\S+)\s+.*($string\.\d+).*$/; print OUT ($1, $pd_file{$2}) if (exists($pd_file{$2}));
complex.1 10.25 complex.2 12.02
Janitored by Arunbear - retitled from 'hash' and balanced code tag around output
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I merge data using a hash?
by Zed_Lopez (Chaplain) on Oct 10, 2004 at 22:01 UTC | |
by Anonymous Monk on Oct 10, 2004 at 22:07 UTC | |
|
Re: How can I merge data using a hash? (golf it)
by ccn (Vicar) on Oct 10, 2004 at 22:40 UTC | |
|
Re: How can I merge data using a hash?
by pg (Canon) on Oct 10, 2004 at 21:57 UTC | |
by Anonymous Monk on Oct 10, 2004 at 22:13 UTC | |
by pg (Canon) on Oct 10, 2004 at 22:15 UTC | |
by Roy Johnson (Monsignor) on Oct 11, 2004 at 15:41 UTC | |
|
Re: How can I merge data using a hash?
by TedPride (Priest) on Oct 10, 2004 at 22:38 UTC | |
by Anonymous Monk on Oct 10, 2004 at 23:00 UTC | |
by TedPride (Priest) on Oct 10, 2004 at 23:35 UTC |