in reply to Merging two data sets
Hi,
As suggested by LanX please find the below code
use strict; use warnings; use Data::Dumper; my %file1hash; my $fin1="./dataset1.txt"; my $fin2="./dataset2.txt"; my ($fh1,$fh2); open ($fh2, "<", "$fin2") or die $!; %file1hash = map{ chomp; split / /; } <$fh2>; print Dumper \%file1hash; close $fh2; open ($fh1, "<", "$fin1") or die $!; while(<$fh1>){ chomp; my ($id, $x1, $x2) = split / /; if (exists $file1hash{$id}) { printf ("%1s %5s %7s %10s\n", $id, $x1, $x2, $file1has +h{$id}); } } close $fh1; exit;
|
|---|