I'm not sure split is the right choice for extracting fixed-length substrings. Isn't that really what substr is for (I mean, if you don't want to use unpack)?
sub split_len { ## split_len( $chars, $string[, $limit] ) ## - splits $string into chunks of $chars chars ## - limits number of segments returned to $limit, if provided my ($chars, $string) = @_; my ($i, @result); for ($i = 0; ($i+$chars) < length($string); $i+=$chars) { last if (defined $limit && @result >= $limit); push @result, substr($string, $i, $chars); } # deal with any short remainders return @result if (defined $limit && @result >= $limit); if ($i > length($string)-$chars) { push @result, substr($string, $i); } return @result; }
In reply to Re: Using split() to divide a string by length
by radiantmatrix
in thread Using split() to divide a string by length
by japhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |