Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 contemplating the Monastery: (6)
As of 2014-12-20 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (94 votes), past polls