in reply to Split string into equal parts
Another way would be to use substr to insert spaces working back from the right-hand end of the string.
$ perl -E ' > $str = q{abcdefghijklmn}; > say $str; > substr $str, $_, 0, q{ } for > grep { ! ( $_ % 4 ) } reverse 4 .. length( $str ) - 1; > say $str;' abcdefghijklmn abcd efgh ijkl mn $
I hope this is of interest.
Cheers,
JohnGG
|
|---|