in reply to file compare and populate
To address the OP Perl, use regexp matching to isolate the first column - which is the correct key for the hash. It also means you then don't need to chop or chomp everything only to have to put the \n back. Also @names doesn't function as an array coercion of %names but as a completely separate piece of storage.comm -13 file1 file2 > file3
The following is now updated to sort the output.
open FIRST,"file1" or die "$!: file1\n"; open LAST,"file2" or die "$!: file2\n"; open NEW,">file3" or die "$!: file3\n"; my %names = (); my %n2 = (); while (<FIRST>) { /^(\S+)/; $names{$1} = 1; } close FIRST; while (<LAST>) { /^(\S+)/; $names{$1} or $n2{$1} = $_; } close LAST; print NEW $n2{ $col1 } for my $col1 ( sort keys %n2 ); close NEW;
-M
Free your mind
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: file compare and populate
by gu (Beadle) on Dec 05, 2005 at 11:03 UTC | |
| |
|