in reply to Split string using regex on \n or max line length
Hi,
I would do it in a string digestion loop:
while ( my $ltd = substr $string, 0, $LIMIT, '' ) { my @parts = split /\n/, $ltd; ... # do sth. with @parts, otherwise they will be sad }
Instead of substr, there are certainly other ways of splitting at fixed length, but this has just come to my mind first.
Update: As $string is rewritten every iteration to another place in memory, haukex' solution performs probably better. Yet I would prefer a while loop instead, swallowing everything in an array first is seldom needed.
|
|---|