in reply to Smart Substrings

my $str = "mom went to the food market today and got me some milk"; my $maxl = 18; my $show; foreach (split(/\s+/, $str)) { if (length("$show $_")+3 >= $maxl) { $show .= '...' and last } else { $show .= " $_" } } print substr($show, 1),"\n";

two things:
1) if you have more than one space between words, it's gonna reduce it to one in resulting string
2) it doesn't do it for $maxl=0 (ie outputs '..')


vsp