G'day rarenas,
Welcome to the Monastery.
I'd probably use a technique more along these lines:
#!/usr/bin/env perl
use 5.014;
use strict;
use warnings;
{
local $/ = "\n>";
while (<DATA>) {
chomp;
substr $_, 0, 1, '' if $. == 1;
my ($head, $seq) = split /\n/, $_, 2;
printf "%-15s %s\n", $head, $seq =~ y/\n//dr;
}
}
__DATA__
>SEQ1
AAA
>SEQ2
AAA
CCC
>SEQ3
AAA
CCC
GGG
>SEQ4 plus ...
AAA
CCC
GGG
TTT
Output:
SEQ1 AAA
SEQ2 AAACCC
SEQ3 AAACCCGGG
SEQ4 plus ... AAACCCGGGTTT
Notes:
-
If you are the Anonymous Monk to whom I responded with "Re: unique sequences" (a couple of days ago),
some of that code should look familiar.
If you're not that person, or just need a revision, see that post for actual I/O
and links to documentation for various elements used in this post.
-
See "perl5140delta: Non-destructive substitution" for the 'r' modifier I've used with y///.
If you're using a Perl version earlier than 5.14, you'll need to do the transliteration
(or transobliteration as it's been called when the 'd' modifier is used) as a separate step
prior to printf.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.