tbone has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my $t = "Call me a joker call me a fool. Right at this moment Im tota +lly cool. Clear as a crystal, sharp as a knife. I feel like Im in t +he prime of my life. Sometimes it feels like I'm going to fast. I d +ont know how long this feeling will last. Maybe its only tomihgt."; my ($string, $i); my $s = length $t; if ($s > 39){ my $i = 39; while ($i < $s){ if ($i == 39){ $i = index($t," ", $i); $string = substr($t, 0, $i); print $string; } else{ my $i2 = index($t, " ", $i+60); if ($i2 == -1){ my $end = substr($t, $i, $s); $end =~s/^\s+//; $string .= "\n" . $end; last; } else{ print $i . " " . $i2 . "\n"; my $end = substr($t, $i, $i2-$i); $end =~s/^\s+//; $string .= "\n" . $end; $i = $i2; } } } } print $string;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: adding newline to middle of a string cleanly
by Roy Johnson (Monsignor) on Dec 09, 2003 at 21:42 UTC | |
|
Re: adding newline to middle of a string cleanly
by Roger (Parson) on Dec 09, 2003 at 22:20 UTC | |
|
Re: adding newline to middle of a string cleanly
by Roy Johnson (Monsignor) on Dec 09, 2003 at 21:53 UTC | |
by tbone (Beadle) on Dec 10, 2003 at 14:44 UTC | |
|
Re: adding newline to middle of a string cleanly
by Sandy (Curate) on Dec 10, 2003 at 01:06 UTC | |
|
Re: adding newline to middle of a string cleanly
by Sandy (Curate) on Dec 10, 2003 at 01:12 UTC |