读书人

Perl 字符串定长瓜分

发布时间: 2012-08-22 09:50:35 作者: rapoo

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;}

读书人网 >perl python

热点推荐