Skip to content

Instantly share code, notes, and snippets.

@JEEN
Last active December 19, 2015 12:19
Show Gist options
  • Save JEEN/5954265 to your computer and use it in GitHub Desktop.
Save JEEN/5954265 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
my $file1 = $ARGV[0];
my $file2 = $ARGV[1];
open my $R, "<", $file1 or die ("Could not open $file!");
open my $P, "<", $file2 or die ("Could not open $file!");
my %data = ();
while (my $Rline = <$R>) {
$Rline =~ s/[\r\n]//g;
my @R_data = split (/\t/, $Rline);
push @{ $data{$R_data[0]} }, \@R_data;
}
while (my $Pline = <$P>) {
$Pline =~ s/[\r\n]//g;
my @P = split(/\t/,$Pline);
if (scalar @{ $data{$P[0]} }) {
for my $row (@{ $data{$P[0]} }) {
print join("\t", @{ $row }, @P)."\n";
}
}
}
close ($P);
close ($R);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment