On Thu, Nov 21, 2002 at 01:41:15PM +0000, Paul Makepeace wrote:
> Perhaps:
>
> my $str = shift @names;
> $str .= ', '.shift @names while 90 > length $str;
> substr($str, rindex($str, ',', 90)) = ", etc." if 90 < length $str;
Gah, premature send, sorry; I meant to add what I originally had,
for ($_ = shift @names) {
$_ .= ", ".shift @names while 90 > length;
s/^(.{1,90}, ).+?$/$1etc./;
}
I guess this breaks with names that have ", " in them though.
Thinking out loud,
for (shift @names) {
$_ .= ", ".shift @names while 90 > length($_ . $names[0]);
s/$/, etc./ if @names;
# use $_
}
This of course messes with @names, so a my @tmp = splice off first
$max_length/(2+1) would solve that.
Ooh fun! This segfaults Debian's v5.6.1 perl,
my @names = ('a') x 3;
for (my ($str, @tmp) = @names) {
shift @tmp;
}
Maybe I should perlbug that.
So I'll stick with,
my ($str, @tmp) = splice @names, 0, 90/3;
$str .= ', '.shift @tmp while 90 > length($str . $tmp[0]);
$str .= ', etc.' if @tmp;
Paul
--
Paul Makepeace ....................................... http://paulm.com/
"What is the history of love? Samba!"
-- http://paulm.com/toys/surrealism/