Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: change \n to \t

by haukex (Archbishop)
on Aug 24, 2019 at 09:12 UTC ( [id://11104935]=note: print w/replies, xml ) Need Help??


in reply to change \n to \t

Note that none of the solutions so far take into account what your original code seems to want to do, which is to only replace newlines before [ATCGN]; OTOH your solution doesn't take into account whether the lines start with > or not. Here is one way that does both, while processing the file line-by-line, thereby saving memory.

use warnings; use strict; my $prevline; while ( my $curline = <DATA> ) { next unless defined $prevline; if ( $prevline=~/^>/ && $curline=~/^[ATCGN]/ ) { $prevline =~ s/\n\z/\t/; } print $prevline; } continue { $prevline = $curline } print $prevline if defined $prevline; __DATA__ >1 AGTCGTAGCAT foo bar >2 TGAGCTACG >3 GGCATAGN quz >4 CGCACNCAGCTACACC >5 NGATAGCTACA

Output:

>1 AGTCGTAGCAT foo bar >2 TGAGCTACG >3 GGCATAGN quz >4 CGCACNCAGCTACACC >5 NGATAGCTACA

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found