I have this snippet;
print "$score\n";
for (my $i = 0; $i < $n; $i++)
{
print $output[$i];
if($i == $center)
{
print "*";
}
print "\n";
}
and it should print this:
-62
ttagggcccgg-a-tc---attaccgggc--caa
tta--gcgcgg-attcg-gatta-cggg---c-a*
gcg--gggcggcattagcaattt-gggg-atc-a
-ta--gcgc---a-----aataa-ccgg------
but instead it prints this:
-62
ttagggcccgg-a-tc---attaccgggc--caa
*ta--gcgcgg-attcg-gatta-cggg---c-a
gcg--gggcggcattagcaattt-gggg-atc-a
-ta--gcgc---a-----aataa-ccgg------
If i remove the “*”, the strings are correct (they are really the strings i want to print), the problem is its placing. this is printed:
-62
ttagggcccgg-a-tc---attaccgggc--caa
tta--gcgcgg-attcg-gatta-cggg---c-a
gcg--gggcggcattagcaattt-gggg-atc-a
-ta--gcgc---a-----aataa-ccgg------
Why is it printing on the beginning of the string, and not on te end as it is supposed to?
Thanks a lot.
Your code works perfectly on a *nix system where
\nis the only line terminator and the lines of text in@outputdo not end in\n.Output:
The only way I see your code generating the output you post is if each line of text contained in
@outputends with a\rwhich would cause the carriage return to occur, then you’d print the*(which would overwrite the first character of the line you just output) followed by the\nat the bottom of your loop.If I change
@outputin my example to:Then the output is:
SO the final answer is: Get rid of the
\rat the end of those. 🙂Edit: As TLP points out in the comments below, using a regex substitution to make sure that there’s nothing on the end of those lines should fix you up:
Last Edit: From the comments below from TLP, I would guess this data is read from a file that came from a windows machine where lines end in
\r\n. When reading that file in perl on OSX, you’re usingchompto remove newlines. In OSX,chompis only going to remove\n(by default) and leave the\rintact.