Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: change \n to \t

by hippo (Chancellor)
on Aug 23, 2019 at 15:28 UTC ( #11104901=note: print w/replies, xml ) Need Help??


in reply to change \n to \t

TIMTOWTDI. I'd abandon the array unless you need it for something else.

#!/usr/bin/env perl use strict; use warnings; my $text; { local $/ = undef; $text = <DATA>; } $text =~ s/\n(?!>)/\t/g; print "$text\n"; __DATA__ >1 AGTCGTAGCAT >2 TGAGCTACG >3 GGCATAGN >4 CGCACNCAGCTACACC >5 NGATAGCTACA

This approach uses a negative look-ahead. It replaces a newline not followed by an angle bracket with a tab. HTH.

Replies are listed 'Best First'.
Re^2: change \n to \t
by yueli711 (Sexton) on Aug 23, 2019 at 15:50 UTC

    Hello, hippo, Thank you so much for your response! Thank you for your help! I really appreciated! Best, Yue

      Actually, my DATA file is huge.
      Then you're probably doing the wrong way using two arrays to store the contents of the file. It is better to read, process and output one line at a time.

      For example something like this:

      open my $IN1, "<", "1.fa" or die "Cannot open input file"; open my $OUT, ">", "1.txt" or die "Cannot open output file"; while (my $line = <$IN1>) { # Do here whatever transformation/substitution you need to $line print $OUT $line; } close $IN1; close $OUT;
      This will be faster and will consume much less memory.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2021-01-19 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?