in reply to Breaking the lines

Text::Wrap seems to do what you want. I think the following regular expression will also do "what you want", as long as there are no words longer than your maximum line lenght:

use strict; my $line_length = 10; my $line = '123 1234 12345 123456 1234567'; my @lines = ($line =~ /(.{1,$line_length}(?:\s|$))/g); print "-" x $line_length,"\n"; print "$_\n" for @lines;

... but I have only cursory tested that idea. I think it will fail for blanks that fall on the last column. Maybe you can fix that by allowing $line_length to be one larger than what fits onto the line.

Replies are listed 'Best First'.
Re^2: Breaking the lines
by Ben Win Lue (Friar) on Jul 19, 2007 at 09:01 UTC
    Thanks a lot!

    Works really good. Now it's my job to spend some spare time and understand the regex!