Hi,
I am having trouble comparing two files of different lengths and extracting a needed value. File 2 has two columns of information that match up with a value from File 1. I use this as search criteria in an IF statement while both files are open. I would like to print File 1 and add the info from File 2(column 10) on the correct line based on my IF statement. I have never used a while statement before but I think its correct. Does it matter that they are of different lengths? I hope this is clear enough. Any suggestions are appreciated.
Thanks
#!/usr/bin/perl
use strict;
use warnings;
my $haul_file = "mack_haul.txt";
my $lands_files = "mack_land.txt";
open (M,">M.txt") || die "Cant open new";
open ("land",$lands_files) || die "cant open\n";
open ("haul",$haul_file) || die "Cant Open\n";
my @Land;
my @Haul;
my $landslines='';
my $haulline='';
while(my $haulline=<haul>){
chomp $haulline;
@Haul=split(/\t/,$haulline);
while(my $landslines=<land>){
chomp $landslines;
@Land =split(/\t/,$landslines);
if ($Land[3]eq$Haul[2])
{
print M "$landslines"."\t$Haul[10]\n";
}
}}}
close(M) || die "GG";
close("haul") || die "Cant close1";
close("land") || die "cant close2";