mismit10:

You've already gotten good answers for your problems. I saw a bit in your code that I thought I would mention, though. One line says:

$final_fragments{$final_fragment2} = $third_fragments[scalar @third_fr +agments - 1];

You're wanting the last value in the array, but that's a funky way to get it. Since you're subtracting one from the value returned by scalar @third_fragments, you're automatically in a scalar context, so you don't really need scalar at all, so it could be simplified to:

$final_fragments{$final_fragment2} = $third_fragments[@third_fragments + - 1];

But perl already has a bit of magic you can use to get the index of the last value in an array: replacing the @ with $# in front of the array name gives you the index of the last value:

$final_fragments{$final_fragment2} = $third_fragments[$#third_fragment +s];

Even more interesting, perl has another bit of magic: Using negative index values you can access values from the end of the array, so -1 is the last element, -2 is the element before the last element. So you could use:

$final_fragments{$final_fragment2} = $third_fragments[-1];

Here's a quick example:

roboticus@sparky:~$ cat t.pl #!/usr/bin/perl use strict; use warnings; my @foo = (5, 7, 9, 11, 13); print $foo[scalar @foo - 1], "\n"; print $foo[@foo - 1], "\n"; print $foo[$#foo], "\n"; print $foo[-1], "\n"; print $foo[-2], "\n"; print $foo[-3], "\n"; roboticus@sparky:~$ perl t.pl 13 13 13 13 11 9 roboticus@sparky:~$

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Bioinformatics, Error: explicit package name by roboticus
in thread Bioinformatics, Error: explicit package name by mlsmit10

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.