in reply to compare two files and update
use strict; use warnings; use Data::Dumper; # Read files into an array and populate a hash my($key1, $key2, %hash1, %hash2); open (IN1,'<'.$ARGV[0]) || die "***can't open the file $!\n"; my $col1 = $ARGV[2]; my $col2 = $ARGV[3]; my @lines1 = <IN1>; close IN1; #$i=0; # Master for (@lines1) { chomp; my @a1 = split(/\t/, $_); my $key1 = $a1[$col1]; $hash1{$key1} =$_ } # check if key in file2 exists in file1 and if so merge the files open (IN2,'<'.$ARGV[1]) || die "***can't open the file $!\n"; my @lines2 = <IN2>; close IN2; #open (OUT,'>'.$ARGV[2]) || die "***can't open the file $!\n"; # slave for (@lines2) { chomp; my @a2 = split(/\t/, $_); my ($key2) = $a2[$col2]; $hash2{$key2} = $_; $hash1{$key2} = $hash2{$key2}; } for my $key (sort keys %hash1) { print "$hash1{$key}\n"; } exit;
|
|---|