I am sorry if this is slightly off-topic (not really though, but I admit it does not really answer your original question), but I do not wish to read and try to understand code that is so poorly formatted. Even though the compiler does not care about it, indenting properly is not an option, it is a necessity, it is of the essence of programming.

Assuming I was asking job candidates to write a short Perl program in order to rate their capacity, I would simply not hire somebody producing such code, even if the program result was correct, because this is just far too sloppy (I am sorry, don't take this a personal critique, but really as an advice and opportunity to improve). Now, the reality is that we are not doing Perl tests for new candidates, because we don't care that much if they know Perl; we use many technologies, Perl is just one of them, and they will have to learn it eventually. But the point is that I would not hire anyone writing such poorly formatted code in any programming language. In other words, to me, writing clean code is in my view a much more important asset than any specific language skills.

Using correct and consistent indentation (irrespective of various coding styles among which you might pick one or the other) is one of the keys to understand what you write, to make it understandable to the coworkers that will have to maintain your code and also to explaining your intentions to the reader (this is essential: if I know, through formatting, what you mean, then I have a fair chance to find a possible bug; if I do not even know what you intended to do, then there is a significant chance that I'll be lost). If you have to, use a code prettifier such as Perl::Tidy or perltidy, but I would encourage you to write tidy code in the first place, because it greatly helps you to better think your code.

Just a couple examples to explain. You have:

my $i = 0; foreach my $match(@exonic_matches) { $value = $exon_ID[$i]; $col = $exon_left{$value}; #...
Everything that is within the opening brace at the end of the first line should be indented. In addition, although this is less important, if you want to insert vertical spaces, put them before the foreach line, not after. So this could be:
my $i = 0; foreach my $match(@exonic_matches) { $value = $exon_ID[$i]; $col = $exon_left{$value}; #... }
or possibly:
my $i = 0; foreach my $match(@exonic_matches) { $value = $exon_ID[$i]; $col = $exon_left{$value}; #... }
depending on your preferred style.

Similarly, your code:

if ($strands{$value} =~ m/\+/) { $diff_three_prime = $LBP[$i] - $three_prime_ss[$exons2{$value} - 1 +]; $diff_five_prime = $LBP[$i] - $five_prime_ss[$exons2{$value} - 1]; + # ...
would be much better rewritten this way:
if ($strands{$value} =~ m/\+/) { $diff_three_prime = $LBP[$i] - $three_prime_ss[$exons2{$value} + - 1]; $diff_five_prime = $LBP[$i] - $five_prime_ss[$exons2{$value} - + 1]; # ...
Just to state it once more, this is not a matter of taste, this is essential to good programming. I do not really care which formatting style you choose (K&R, GNU, Microsoft, ...), but the formatting has to be consistent and to show the structure of your program.

And, again, I am really not writing this to chastise you in any way, but to try to help you using better programming practices. Really do it, I am sure that you will see the benefits fairly quickly.


In reply to Re: looping foreach error by Laurent_R
in thread looping foreach error by Anonymous Monk

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.