in reply to Use of Uninitialized in Concatenation or String Error?

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

Replies are listed 'Best First'.
Re^2: Use of Uninitialized in Concatenation or String Error?
by ccelt09 (Sexton) on Aug 09, 2013 at 11:08 UTC

    Thank you for the well thought out and thorough feedback, this helped me immensely! I worked back through the program paying special attention to layout. I also noticed I said the 5th element when indeed it was the fourth element, or 3rd array slice, that corresponded to chromosome locus.

    Currently the revised program will print the correct number of output files and increments the position and placeholder variables correctly :). All the files are blank because, as you said, start and end values don't change so the test is always FLASE. This is because the starting locus in my data sits at the 2.6 million mark, while $start = 1 and $end = 1,000,001

    It seems unnecessarily convoluted but also within the scope of my perl knowledge base to assign two more place-holding variables to $start and $end respectively, incrementing them within the else loop when the test is FALSE. I think this will work but I have to think about how to accomplish this. Thanks again, Ken.