I am using Perl to generate a SELECT pull-down in an HTML form. I'd like to limit the length of the text that gets shown, so that the menu doesn't become too wide. I'm trying to figure out the best method for doing this.
For the sake of argument, lets say...
I want a maximum string length of 15 characters
The text for the OPTION is coming from a database, and can contain spaces and punctuation
I want to chop long entries between words and add a "..." to the end
Thought 1
Compare string length against maxlength
If stringlength>maxlength, use a regex to chop off the end at a whitespace, and concatonate a "..."
Compare new stringlength against maxlength and repeat if necessary
Thought 2
Similar to above, but use split to put all of the words into a temporary array, then reconstruct the string, leaving out words as necessary