A1 Transcendence has asked for the wisdom of the Perl Monks concerning the following question:

Enlightened Monks, I have recently taken up Perl programming and i am falling in love with it. I am learning new things every day and having a blast;).

Today i am writing in order to obtain some wisdom on my current topic. My task is to write a fairly simple Perl program that 1) Opens a large 1000 genome file. 2) Opens 75 different Files each with 50 IDentifiers 3) In a loop...Starting with File 1 Identifier 1 if (File 1 ID 1 matches 2nd column of the 1000 genome file) extract the whole line from the 1000 genome file and store it in an output that is labeled File1_out. Lastly increase the ID to the 2nd element of 50. Do this for all the identifier in File 1, then after 50th ID open File2 and do the same thing again. Basically do this for all of the 75 Files. I think i should only open each of the files one time and work with arrays. Below is my script that i have been working/struggling on for a couple of days. I know the task can be done in under 10 lines but i have over complicated my code and need some help. Below is what i have done so far. Please share some of your ideas oh wise monks.

#!/usr/bin/perl $CHR_NUM = $ARGV[0]; $file_location = "/home/ALL.chr$CHR_NUM.phase1_release_v3.20101123.snp +s_indels_svs.genotypes.vcf.gz"; for $x (1..75) { open (FH, "/home/raj/HAPLOTYPES_JAN_2015/PROG_1_Approach_2/C22 +-$x")|| die "Cannot"; while (<FH>){ chomp $_; push (@{$x} , $_);#this loop opens the 75 files with i +dentifier and stores in arrays } } open(IN, "zcat $file_location |") || die "can't open CHROMOSOME $CHR_N +UM input file 1000G!"; $g=1; $z=0; while (<IN>) { $choice = 1; $x=$g; $y=$z; chomp $_; $counter ++; LABEL: if ($choice == 1){ if ($counter > 29) { # print "$_\n"; @currentline = split (/\t/, $_); #print "$currentline[1]\n"; for $r($x..75) { # $r will be used as the name +s for files 1-75 for $t ($y..$#$r) { if ($currentline[1] == $$r[$t] +) { open ($r,">>$r"); print $r "$_\n"; $z = $t++; $choice = 0; goto LABEL; } } } } } if ($z >= $#$x){ $g = $x++; $z = $y = 0; close $r; if ($x==76){# last; } } }

I know this should be done using only several lines but my shortcut techniques are still not advanced. Any wisdom will be greatly appreciated.