Hello andybshaker,

Others have answered your immediate question, but I want to comment on this part of your code:

open(IN, "<$file") or die "Cannot open file $file\n"; my @lines = <IN>; foreach $1 (@lines){ chomp($1); my %columns = split(">", $1); } close(IN);

(I have reformatted it a little to make it clearer.) First, the use of $1 as a loop variable is — well, unusual, to say the least. Normally, $1 contains the first matched string in the last regular expression match. In idiomatic Perl, the variable $_ is used implicitly:

foreach (@lines){ chomp; my %columns = split(">"); }

But second, and much more importantly, this foreach loop does literally nothing. You create a lexical variable %columns and fill it with split; then re-create it on the next iteration of the loop; and so on. And when the loop ends, the variable — having been declared within the scope of the loop — goes out of scope and is (eventually) garbage-collected. The contents of the file remain unchanged.

And a final point: Please, please get into the habit of using a sane code formatting (indenting) style for nested loops. For example:

foreach my $G (@Genes){ for my $x (0 .. $#ptt){ if ($ptt[$x] =~ /$G/){ push(@Coordinates,"$ptt[$x]"); print "$ptt[$x]\n"; } } }

Why make your code harder to read than it needs to be? The maintenance programmer who comes to look at the code in six months time may well be you!

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Getting an unknown error by Athanasius
in thread Getting an unknown error by andybshaker

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.