Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: how to escape new line in a string

by Athanasius (Archbishop)
on Jun 16, 2019 at 08:37 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11101426]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-23 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found