G'day ccelt09,
There's some fundamental flaws in your code.
"I then receive a continuous
Use of uninitialized value within @SNPs in concatenation (.) or string at temp_file_test.pl line 36, <CG> line 1112424."
You're in an infinite loop! As soon as you enter "while ($switch == 1) {", you perform a test: "(($position < $end) && ($position >= $start))". Obviously, that test must have been TRUE on the first iteration or you would never reach line 36. The only way to exit the loop, is to set the value of $switch to something other than 1; you only do this if the aforesaid condition is FALSE but, the variables involved in that condition ($start, $end and $position) never change within the loop, so the loop never ends!
At line 36 you have: "print OUT "$SNPs[$placeholder]\n";". The variable $placeholder in incremented (infinitely) a few lines below this: "$placeholder++;". At some point, the index exceeds the number of assigned elements in @SNPs and you start getting "uninitialized value" warnings.
"I print out the correct first temp_2.txt file but no lines are printed to it"
In your infinite loop, you open an output file like this: "open(OUT, ">$output_file");". Every time you call this, you delete $output_file and create a new one (see open, taking particular note of the 3-argument form shown in the examples). When you kill the script, $output_file will probably have a size of 1 and contain a single newline.
There are other discrepancies between your description and code but I'm not sure which is correct. You talk about the locus being the fifth element but nowhere do you access the fifth element of anything. Your initial code (but not description) has a "chrX_1Mbwindow_nonoverlapping.interval file; I see you mention this elsewhere in the thread but you show (what should be unique) ranges as: 1000001-2000001, 2000001-3000001.
So, fix those problems first (both code and data) and maybe other issues (such as "spaces at the end of my input file" — whatever the significance of that might be) will resolve themselves. When you read the open documentation, take note of $! and see perlvar if you don't know what it is. You'd also do well to take a look at perlstyle for some tips on code layout: what you've posted is messy, not that easy to read and a potential source of errors.
-- Ken
In reply to Re: Use of Uninitialized in Concatenation or String Error?
by kcott
in thread Use of Uninitialized in Concatenation or String Error?
by ccelt09
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |