logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: limit the list: msg#00083

Subject: Re: limit the list
On Wed, 20 Nov 2002 21:01:45 +0100
"A. Pagaltzis" <pagaltzis@xxxxxx> wrote:

> * Jonathan E. Paton <jonathanpaton@xxxxxxxxx> [2002-11-20 20:51]:
> > if (@array > $bound) {
> >     $array[$bound-1] = ", etc"; # Set element at boundary 
> >     $#array = $bound-1;         # Shorten array to boundary
> > }
> > 
> > print join ", ", @array;
> 
> Again, that's the same as:
> 
> join ', ', @array[0 .. $bound], @array > $bound ? 'etc' : ();

both are wrong. how can you be sure the resulting string will be
no more than 90 chars (X chars) in length?

for example the first element in the array is 128K :)

> 
> > Now, this I *might* use in production code.  Of course, the
> > obvious mistake is that space between the last element and
> > the ", etc" part - but easily solved by using .= to append
> > to the appropriate element.
> 
> No, it will look like "..blah, , etc" and that's easily
> remedied by using just "etc" since the join adds its own
> ", " anyway.
> 
> -- 
> Regards,
> Aristotle
> 


-- 
Vladi Belperchinov-Shabanski <cade@xxxxxxxxxx> <cade@xxxxxxxxxx>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...

Attachment: pgpDbQKw5ncO2.pgp
Description: PGP signature


Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>