Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: how to escape new line in a string

by Athanasius (Bishop)
on Jun 16, 2019 at 08:37 UTC ( #11101426=note: print w/replies, xml ) Need Help??


in reply to how to escape new line in a string

Hello nica,

If you look carefully at this line:

print OUT "Genome: \n $line\n"; # ^^ ^^

you will see that you are adding the newlines yourself! Here is one approach that does what you want:

use strict; use warnings; print 'Genome: '; while (my $line = <DATA>) { $line =~ s/^[0-9]+//; # Remove initial digits $line =~ s/\s+//g; # Remove all whitespace (including newline +s) print $line if $line =~ /[acgt]+/; } print "\n"; __DATA__ INPUT ORIGIN 1 ccctaaaccc taaaccctaa accctaaacc ctaaacccta aaccctaaac cctaaaccct 61 aaaccctaaa ccctaaaccc taaaccctaa accctaaacc ctaaacccta aaccctaaac 121 cctaaaccct aaaccctaaa cgatgcatta ctactcacac gaacgagtga atgaaacaca

Output:

18:35 >perl 2007_SoPW.pl Genome: ccctaaaccctaaaccctaaaccctaaaccctaaaccctaaaccctaaaccctaaaccctaa +accctaaaccctaaaccctaaaccctaaaccctaaaccctaaaccctaaaccctaaaccctaaacccta +aaccctaaacgatgcattactactcacacgaacgagtgaatgaaacaca 18:35 >

Hope that helps,

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11101426]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-07-13 08:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?