在 Perl 中将字符串拆分为等长块 [英] Split a String into Equal Length Chunk in Perl
本文介绍了在 Perl 中将字符串拆分为等长块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个长度为 3 的倍数的字符串.
Let's say I have string of length in multiple of 3.
my $seq = "CTTCGAATT"; # in this case length of 9
有没有办法把它分成等长的 3?这样我最终就有了这个数组:
Is there a way I can split it into equal length of 3? Such that in the end I have this array:
$VAR = ["CTT", "CGA", "ATT"];
推荐答案
查看解决方案 How can I split a string在 Perl 中分成两个字符的块?
特别是 unpack
可能很有趣:
Especially the unpack
might be interesting:
my @codons = unpack("(A3)*", $seq);
这篇关于在 Perl 中将字符串拆分为等长块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文