Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Unicode word wrapping

by ph0enix (Friar)
on Dec 09, 2002 at 09:40 UTC ( [id://218485]=note: print w/replies, xml ) Need Help??


in reply to Unicode word wrapping

I don't know what can be wrong...

What about following code?

... use utf8; my $max_text_len = 40; ... sub split_text { my $intext = shift || return ''; my @result = (); my $index = 0; foreach my $word (split(' ', $intext)) { next if !length($word); if (length("$result[$index] $word") > $max_text_len) { $index++; $result[$index] = $word; } else { $result[$index] .= ($result[$index] ? ' ' : '').$word; } } return join("\n", @result); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-06-17 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.