Splitting up long words

M

Marcus

Hi

In perl, what is the smotthest way of splitting up words longer than x
characters?

Ex.

From a textfield I have $text (max 400 characters in total)

I want to print $text, but while doing that split any words longer
than 10 characters long through inserting a space

If $text = "this is a sample text and now here is
averylongwordthatwouldmessupthelinebreaks"

The result, when printed out, would be:

"this is a sample text and now here is averylongw ordthatwou
ldmessupth elinebreaks"


Thanks!
 
B

Ben Morrow

Quoth (e-mail address removed) (Marcus):
Hi

In perl, what is the smotthest way of splitting up words longer than x
characters?

Ex.

From a textfield I have $text (max 400 characters in total)

I want to print $text, but while doing that split any words longer
than 10 characters long through inserting a space

If $text = "this is a sample text and now here is
averylongwordthatwouldmessupthelinebreaks"

The result, when printed out, would be:

"this is a sample text and now here is averylongw ordthatwou
ldmessupth elinebreaks"

<untested>
1 while $text =~ s/(\S{10}\S)/$1 $2/;

Ben
 
T

Tore Aursand

In perl, what is the smotthest way of splitting up words longer than x
characters?

If you're looking for _flexible_ solutions, please take a look at the
Text::* modules, especially Text::Wrap and Text::Autoformat.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top