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

Re^2: How to split a string based on length or word boundary

by Athanasius (Monsignor)
on Dec 21, 2012 at 02:54 UTC ( #1009837=note: print w/ replies, xml ) Need Help??


in reply to Re: How to split a string based on length or word boundary
in thread How to split a string based on length or word boundary

Brilliant++!

Just needs a couple of tweaks:

print "| $_ |\n" for map substr($_ . ' ' x 16, 0, 16), $s =~ m[(.{1,16 +})(?:\s+|$)]g; # ^^ + ^^^^^^^^^

(Otherwise, the final word won’t be printed unless it happens to be followed by whitespace.)

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re^2: How to split a string based on length or word boundary
Download Code
Re^3: How to split a string based on length or word boundary
by BrowserUk (Pope) on Dec 21, 2012 at 03:04 UTC

    Good point about the $++

    The \n is provided by -l in my code.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-11-28 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (196 votes), past polls