#!/usr/local/bin/perl -w use strict; my $string = <<END; Lorem Ipsum is simply dummy text of the printing and typesetting indus +try. Lorem Ipsum has been the industry's standard dummy text ever since the + 1500s, when an unknown printer took a galley of type and scrambled it to make + a type specimen book. It has survived not only five centuries, but also the l +eap into electronic typesetting, remaining essentially unchanged. It was popula +rised in the 1960s with the release of Letraset sheets containing Lorem Ipsum p +assages , and more recently with desktop publishing software like Aldus PageMa +ker including versions of Lorem Ipsum. END my $trunk = substr($string,0,50); # cut to 50 chars $trunk =~ s/\S+$//; # remove ending non-whitespace $trunk =~ s/\s+$//; # remove ending whitespace print "'",$trunk,"'\n";
It guarantees a maximum of 50 chars, but it cuts off the last word if it ends on the 50th char.
In reply to Re: Rounding to the nearest word
by Joost
in thread Rounding to the nearest word
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |