A. Pagaltzis wrote:
> * Dave Arnold <[EMAIL PROTECTED]> [2002-11-21 02:45]:
>
>>$str = join ', ', @names;
>>if ( length($str) > 90 )
>>{
>> substr($str,rindex($str,",",90)) = ", etc.";
>>}
>
>
> Nice, and so obvious too - in retrospect, of course.
>
> The only thing I don't like about it is it still joins
> everything, even if it only needs 3 out of 10,000 elements.
>
How about a simple change of the first line to:
$str = join ', ', @names[0..30];
With a "," and a " ", each element must have at least 3 characters
(ignoring the posibility of empty elements), so there will be at most 30
entries in the final string. I include the 31st to trigger the
", etc.".
[Others have presented very similar ideas]
Chris