It is possible to use split for this, but the only solution I know of requires a filtering through grep:
@codons = grep $_, split /(.{3})/, 'atgactaatagcagtgg';
As demerphq pointed out, unpack is a better way to achieve this. But if you're going to use split, note that that grep condition is wrong. In particular if the last character is a zero and it should be in an an element of its own then it will get omitted:
my @codons = grep $_, split /(.{3})/, 'atgactaatagcagt0';Explicitly testing for the empty string is required:
my @codons = grep { $_ ne '' } split /(.{3})/, 'atgactaatagcagt0';Smylers
In reply to Re: Puzzlement in Splitsville
by Smylers
in thread Puzzlement in Splitsville
by tlm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |