Hello nikkk,

As ww says, those of us who are not biologists can only guess at what your script is doing. It would help us a lot if you included a (short!) example, showing input data (the contents of $query and $nomefile) together with the desired output. In the meantime, I’ll offer two pieces of advice on your code:

First, always use warnings; As it happens, this won’t produce any warnings for your existing code. Nevertheless, it’s something you should get in the habit of using for every script.1 Why operate without a safety net when you don’t have to?

Second, declare variables only when you need to, not all together in a block at the head of your script. This is better style, and it has the advantage that it makes it much easier to see the relation between a variable’s declaration and its use(s). In the present case, the variable $length is declared near the top of the script, and then not used again until the very end:

my $length; ... if(exists $oligo{$query} || exists $oligo{$revcomp}) { ... } else { print("$revcomp\t appear $oligo{$revcomp} times\t in position ($le +ngth - @{$pos{$query}}) on negative strand\n"); # ^^^ +^^^^ }

— at which point it is guaranteed to have a value of undef, which converts numerically to zero. I doubt this is what you intended. Declaring $length as late as possible (i.e., immediately before the point at which it is first used) would have alerted you to the fact that it’s not being assigned its correct value.

Update: Also, the scalar variable $oligo is declared but never used. This fact is somewhat obscured by the various appearances of $oligo{...}, but they reference the hash variable %oligo.

1Yes, even one-liners. perl -wE is just as easy to type as perl -E. :-)

Hope that helps,

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


In reply to Re: homemade blat: need help with reverse string. by Athanasius
in thread homemade blat: need help with reverse string. by nikkk

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.