Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have two files e.g.
I need to compare column 1 of file2 with column1 of file1file 1 ------ a 0 c 1 d 1 e 3 f 0 file 2 ------ a 0 b 0 c 0 d 0 e 0 f 0
The code I have for this so far (which doesn't work) isfile3 ----- a 0 b 0 c 1 d 1 e 3 f 0
This is just creating file3 as a complete copy of file2.open FIRST,"file1" or die "Can't open file1: $!\n"; open LAST,"file2" or die "Can't open file2: $!\n"; open NEW,">file3" or die "Can't open file3: $!\n"; chomp (my @last=<LAST>); my %names; @names {<FIRST>} = (); foreach my $name (@last) { next if exists $names { $name }or print NEW "$name\n"; } close FIRST; close LAST; close NEW;
How do I get it to just compare the first element of each record ?
How do I get the new record inserted in the correct order in the new file ?
Any help appreciated, I'm really struggling with the logic on this one
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file compare and populate
by Moron (Curate) on Dec 05, 2005 at 10:52 UTC | |
by gu (Beadle) on Dec 05, 2005 at 11:03 UTC | |
| |
| |
|
Re: file compare and populate
by vennirajan (Friar) on Dec 05, 2005 at 12:43 UTC | |
by Anonymous Monk on Dec 05, 2005 at 13:06 UTC | |
|
Re: file compare and populate
by Moron (Curate) on Dec 05, 2005 at 15:15 UTC |