`
fcmfcm01
  • 浏览: 65755 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Perl 字符串定长分割

    博客分类:
  • Perl
阅读更多

Perl 字符串按照给定的长度分割并返回数组

 

sub splitStr {
	my ( $strtmp, $length ) = @_;
	my $strLength = length $strtmp;
	my @results;
	for ( my $i = 0 ; $i < $strLength ; $i += $length ) {
		#if length reach the bound , just resturn the left ones 
		if ( $strLength < ( $i + $length ) ) {
			push @results, substr( $strtmp, $i );
		}
		else {
			push @results, substr( $strtmp, $i, $length );
		}
	}
	return \@results;
}
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics