use strict; use warnings; my @scaffolds; { local $/ = undef; open(IN,"t.txt") or die; @scaffolds = split(/(>scaffold\d+)\n/, <IN>); } close IN; my $i; my $s; foreach (@scaffolds) { if (/^>/) { $s = "$_."; # assemble label for this scaffold $i = 1; # and initialize its counter } else { print map { "$s." . $i++ . "\n" # print incremented label . $_ # and the GACT* stuff } split(/(?:N{4,}\n)+/, $_); # for each entry within the + scaffold } }
Sorry for changing all the variables on you. And one subtle detail worth noting is the parens in the first split!
Update:I changed the first split from split(/>scaffold(\d+)/, <IN>); to split(/(>scaffold\d+)\n/, <IN>);. This simplifies the assignment of $s and obviates the stripping of whitespace in map.
In reply to Re: Conditionally Substituting multi-line string with single string
by hbm
in thread Conditionally Substituting multi-line string with single string
by Osiris1975
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |