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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.