in reply to Bioinformatics, Error: explicit package name

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.