All pastes #987350 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-04-16 13:52 UTC
rendered paste body
sub wrap {
# intelligent wrap
        my ($l, $msg) = @_;           # are passed parameters, length and original text.
        my ($temp, @newmsg, $l2);     # working vars.
        return unless (defined $msg); # return if original $msg empty

        $temp = $msg;
        while (length($temp) > $l)    # while length of working copy of $msg is 
longer than desired line length
        {
                $l2 = $l;
                $l2-- while (substr($temp,$l2-1,1) ne " ");
                push @newmsg, substr($temp,0,$l2);
                $temp = substr($temp,$l2);
        }

        push @newmsg, $temp;
        return join("\r\n", @newmsg);
}