#!/usr/bin/perl use strict; use warnings; my $sum = 0; #open(my $datamap, '<', "mapping.txt") or die "Could not open '$file' $!\n"; open(my $data2, '<', "file2.txt") or die "Could not open '$file' $!\n"; while (my $line = <$data2>) { chomp $line; my @fields = split "^", $line, -1; my $col2Val = $fields[1]; my $col1Val = $fields[0]; my $col3Val = $fields[2]; my $col4Val = $fields[3]; if (! defined $firstHashRef->{$col2Val}) { $firstHashRef->{$col2Val}->{Col1} = $col1Val; $firstHashRef->{$col2Val}->{Col3} = $col3Val; $firstHashRef->{$col2Val}->{Col4} = $col4Val; } } close($data2); open(my $data1, '<', "file1.txt") or die "Could not open '$file' $!\n"; while (my $line = <$data2>) { chomp $line; my @fields = split ",", $line, -1; my $col1= $fields[1]; my $col4= $fields[3]; my $col6= $fields[5]; my $genmapping="grep '$col4\t$col6' $datamap"; my $mapping=`$genmapping`; if($mapping) { my $mapfound=split "\t", $mapping -1; if ((defined $firstHashRef->{$col1}) && ($mapfound[2]==$firstHashRef->{$col1}->{Col1}) ) { $fields[3]=$mapfound[0]; $fields[5]=$mapfound[4]; $fields[8]=$firstHashRef->{$col1}->{Col3}; $fields[9]=$firstHashRef->{$col1}->{Col4}; print OUT join( ',', @fields ) . "\n" ; } else { warn "We did not locate entry in hash table \n"; } } else{ $fields[3] = "unlim"; print join( ',', @fields ) . "\n" ; } } close($data1);