in reply to Forcing a string with no spaces to wrap to fit on the screen

Ok thanks for the comments, I feel i'm getting close to a solution now... (I hope anyway)

I have this code

my $subject = "sdfsdfasdfaskjhasdkhdglkjhsdgkljhdgfkjhdasfjhkljsdahgkl +sjgkajshgfkaljdghdalkhj etc"; my $maxsize=125; push(@parts, substr($subject, 0, $maxsize, '')) while length $subject;

This will break the string up into an array in sizes of $maxsize characters, however what I want to do is slightly cleverer. I want to split up the string based on spaces, then if it gets to greater than the maxsize without a space, then split there.

So split on spaces, unless the part gets to be more than 125 characters, in which case split anyway.

Thanks,
Tom