in reply to Breaking String

Maybe I have this wrong.
use strict; use warnings; my $maxlen = 60; my $finalbuffer = undef; my $smstext = $ARGV[0]; if ($smstext=~s/^(.{0,$maxlen})(?:\s|$)//) { $finalbuffer.=$1; $finalbuffer.="\n".$1 if ($smstext=~s/^(.{0,$maxlen})//); } print $finalbuffer

Replies are listed 'Best First'.
Re^2: Breaking String
by periapt (Hermit) on Oct 17, 2008 at 19:44 UTC
    This code splits the second line in the middle of the word "characters". On the other hand, if you use the same regex as in the first match, it seems to work.

    PJ
    use strict; use warnings; use diagnostics;