in reply to Re^2: Display shortened paragraph
in thread Display shortened paragraph
The rindex function, like substr, is faster than a regex match.my $maxlen = 20; my $longtext = "This is some very long string that needs to be truncat +ed to $maxlen characters..."; my $trunctext = substr( $longtext, 0, rindex( $longtext, " ", $maxlen +)); print "$longtext\n$trunctext\n";
|
|---|