in reply to How do I truncate a string while preserving words?
Try
that should work as expected (at least as far as the presented code goes...).$string =~ s/^(.{0,$maxlength})\b.*$/$1.../s;
Edit: explanation: you can ommit the upper bound, but not the lower bound, as you did. From perlre:
and you have to match the rest of the input (.*$) for it to be replaced too - otherwise you would simply insert the ellipsis (...) without truncating the input.{n}? Match exactly n times {n,}? Match at least n times {n,m}? Match at least n but not more than m times
regards,
tomte
An intellectual is someone whose mind watches itself.
-- Albert Camus
In Section
Seekers of Perl Wisdom