-- Michael G Schwern <[EMAIL PROTECTED]>
On Wed, Nov 20, 2002 at 02:07:18AM -0600, Steven Lembark wrote:
> my ($i, $total);
> ($total += length) < 90 ? $i++ : last for @ARGV;
> $str = join ', ', @ARGV[0 .. $i];
> $str .= ', etc' if $i < $#ARGV;
my $a = substr join( ',', @namz ), 0, 89;
$a .= ',etc...' if length $a == 90;
That was my first try, but it doesn't work since the substr will often
cut off in the middle of a word and you wind up with things like
"foo,foo,f,etc..."
Also, substr()'s LENGTH argument is just that. Its not one-off like an
array index. If you want 90 characters you say 90 not 89.
With caffene...
e.g., my $string = commify 90, ', ', 'etc...', @namz;
sub commify
{
my ( $max, $sep, $end ) = ( shift, shift, shift );
my $sum = 0;
# if $end can dangle use $cut = $max.
my $cut = $max - length $sep;
my $sln = length $sep;
join $sep,
map
{
$sum < $cut ?
( ($sum += $sln + length) < $cut ? $_ : $end )
:
()
}
@_
}
--
Steven Lembark 2930 W. Palmer
Workhorse Computing Chicago, IL 60647
+1 800 762 1582