Of course, if a name is longer than 45 char's this will silently eat the start of that name. Im not sure if its at all possible to handle this nicely with a regexp, at least I have never managed to do it. Problems is how to handle the case where you cant break the input the way you want.
Now, it wasn't really specified how to handle this situation, maybe break on whitespace instead? Or just simply overflow? (One application I work with frequently will hang forever trying to break a line longer than 80 characters if there are no spaces in it:-). Anyway, if overflowing is the solution for this particular problem, then Text::Wrap might come to the rescue:
use Text::Wrap qw(wrap);
my @parts=do {
local $Text::Wrap::columns=45;
local $Text::Wrap::huge='overflow';
local $Text::Wrap::separator=",\n";
local $Text::Wrap::break=qr/\s*,\s*/;
split /\n/, wrap('','',$string);
};
gc
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.