This is my first attempt. My misunderstanding was in the fact that I could put the filehandles inside another filehandles while loop.
#!perl use strict; &read_the_files; sub read_the_files{ print "\nread_the_files";# my$file1 ="./file1.txt"; #contents of file1.txt #1;;;; #6;;;; my$file2 = "./file2.txt"; #contents of file2.txt #;;;;5 #;;;;10 my$file3 = "./file3.txt"; #contents of file3.txt #;;;4; #;;;9; my$file4 = "./file4.txt"; #contents of file3.txt #;;;;5 #;;;;10 my$writing = "./combined.txt"; my$count; unless(open(FH, $file1)){print "\nCouldn't read $file1";exit}else{print "\nOpen successful"} ####################### #this next bit of code seems old and sloppy. I would have to do it on all the files to get the last line number # is there a newer way? my$test = <FH>; while( <FH>){$count = $.;} close(FH); print "\ncount: ".$count; ####################### unless(open(FH1, $file1)){print "\nCouldn't read $file1";exit}else{print "\nOpen successful"} unless(open(FH2, $file2)){print "\nCouldn't read $file2";exit} unless(open(FH3, $file3)){print "\nCouldn't read $file3";exit} unless(open(FH4, $file4)){print "\nCouldn't read $file4";exit} unless(open(FHW, ">$writing")){print "\nCouldn't write to $writing";exit;} #get the info for each line and put it into the database line by line this will use less memory while($count--){ print "\n reading filehandle"; my($line1,$line2,$line3,$line4); $line1 = <FH1>;print "\nline1: $line1"; $line2 = <FH2>;print "\nline2: $line2"; $line3 = <FH3>;print "\nline3: $line3"; $line4 = <FH4>;print "\nline4: $line4"; #putting content in empty spaces so full aray will register $line1 =~ s/;;/;`;/g; $line2 =~ s/;;/;`;/g; $line3 =~ s/;;/;`;/g; $line4 =~ s/;;/;`;/g; #the sizes of these arrays may vary by one so I have to find the greatest one [EMAIL PROTECTED] = split(";", $line1); [EMAIL PROTECTED] = split(";", $line2); [EMAIL PROTECTED] = split(";", $line3); [EMAIL PROTECTED] = split(";", $line4); my$n1 = @insert1; my$n2 = @insert2; my$n3 = @insert3; my$n4 = @insert4; [EMAIL PROTECTED] = [$n1,$n2,$n3,$n4]; print "\n ns : $n1,$n2,$n3,$n4"; [EMAIL PROTECTED] = sort { $b <=> $a } @ns; [EMAIL PROTECTED]; for(my$i=0;$i<7;$i++){ if($insert1[$i] =~ /\w/){$mainline[$i] = $insert1[$i]} if($insert2[$i] =~ /\w/){$mainline[$i] = $insert2[$i]} if($insert3[$i] =~ /\w/){$mainline[$i] = $insert3[$i]} if($insert4[$i] =~ /\w/){$mainline[$i] = $insert4[$i]} } my$printline = join(";", @mainline); #remove backtics that had no values $printline =~ s/`//g; print FHW $printline."\n"; } } #add to mysql table after FWH is updated