Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: breaking up lines along white spaces with max length

by Random_Walk (Parson)
on Feb 02, 2005 at 10:36 UTC ( #427200=note: print w/ replies, xml ) Need Help??


in reply to breaking up lines along white spaces with max length

While pelagic's answer is probably the best way to go here is some script to do it too.

#!/usr/bin/perl use warnings; use strict; my $length=10; while (<DATA>) { my @bits=split; # defaults to splitng $_ on whitespace foreach (@bits) { while ((length $_) > $length) { print "long one\n"; # here we substitute an empty string for the # first $length characters and printing the # ones replaced print ((substr $_, 0, $length, "")."\n"); } print "$_\n"; } } __DATA__ This one is fine ThisOneIsNotReallySoGood Here is a mixedbagoflongbits and then reasonably shortishbutnotshorten +ough

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!


Comment on Re: breaking up lines along white spaces with max length
Download Code
Re^2: breaking up lines along white spaces with max length
by pelagic (Curate) on Feb 02, 2005 at 10:51 UTC
    Carpe diem my dear!

    Update:
    I just realise "Pereant, qui ante nos nostra dixerunt" being your standard "disclaimer" ;)

    pelagic

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-01-31 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My top resolution in 2015 is:

















    Results (257 votes), past polls