Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Breaking the lines

by Corion (Patriarch)
on Jul 19, 2007 at 08:17 UTC ( [id://627464]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://627464]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-23 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found