Re: limit the list

2002-11-20 Thread Steven Lembark
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; -- Steven Lembark 2930 W. Palmer Workhorse Computing

Re: limit the list

2002-11-20 Thread Steven Lembark
-- 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 .=

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Andrew Molyneux [EMAIL PROTECTED] [2002-11-20 12:47]: You're not the only one. I'd probably do: my ($max, $sep, $end) = @_; aolme too/aol but I'd love to know if Steven had a specific reason for doing it the other way. There doesn't seem to be any here. -- Regards, Aristotle

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Abigail
On Wed, Nov 20, 2002 at 11:42:43AM +0100, Bart Lateur wrote: On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my ( $max, $sep, $end ) = ( shift, shift, shift ); ... } Wow! Hold it! Am I the only one who finds this absurd? More than one shift on the

RE: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Moran, Matthew
Abigail wondered: Why is that bad style? Many times when people say it's bad style, it's just a case of beauty is in the eye of the beholder. Strikes me that instead of using one move to assign the variables, it's using three. Matt

RE: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Bernie Cosell
On 20 Nov 2002 at 13:43, Moran, Matthew wrote: Abigail wondered: Why is that bad style? Many times when people say it's bad style, it's just a case of beauty is in the eye of the beholder. Strikes me that instead of using one move to assign the variables, it's using three. Just

Re: AW: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Jonathan E. Paton
--- Pense, Joachim [EMAIL PROTECTED] wrote: Von: Moran, Matthew [mailto:[EMAIL PROTECTED]] Gesendet am: Mittwoch, 20. November 2002 14:41 Joachim suggested: sub commify { my $max = shift; my $sep = shift; my $end = shift; ... } better or even worse in

Re: AW: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Jeremy Impson
On Wed, 20 Nov 2002, Pense, Joachim wrote: Bart Lateur [mailto:[EMAIL PROTECTED]] wrote: (Mittwoch, 20. November 2002 11:43) On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my ( $max, $sep, $end ) = ( shift, shift, shift ); ... } Wow! Hold it! Am I

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Steven Lembark
-- Bart Lateur [EMAIL PROTECTED] On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my ( $max, $sep, $end ) = ( shift, shift, shift ); ... } Wow! Hold it! Am I the only one who finds this absurd? More than one shift on the same array in one single expressing,

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Steven Lembark
-- Andrew Molyneux [EMAIL PROTECTED] Wow! Hold it! Am I the only one who finds this absurd? More than one shift on the same array in one single expressing, sounds like bad style to me. Comments? You're not the only one. I'd probably do: my ($max, $sep, $end) = @_; but I'd love to know

Re: limit the list

2002-11-20 Thread Steven Lembark
-- A. Pagaltzis [EMAIL PROTECTED] * Steven Lembark [EMAIL PROTECTED] [2002-11-20 12:47]: map { $sum $cut ? ( ($sum += $sln + length) $cut ? $_ : $end ) : () } Wasted work. Two comparisons per element and you don't bail once you've filled your available space. Two

Re: AW: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Steven Lembark
-- Pense, Joachim [EMAIL PROTECTED] Bart Lateur [mailto:[EMAIL PROTECTED]] wrote: (Mittwoch, 20. November 2002 11:43) On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my ( $max, $sep, $end ) = ( shift, shift, shift ); ... } Wow! Hold it! Am I the only one who

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Steven Lembark [EMAIL PROTECTED] [2002-11-20 17:35]: Yes, becuase if you did it this way you'd get $end equal to the integer coult of the number of list arguments passed plus one for the end value. Notice the usage: my $string = commify 90, ', ', 'etc...', @names; The other

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Steven Lembark [EMAIL PROTECTED] [2002-11-20 17:35]: Wasted work. Two comparisons per element and you don't bail once you've filled your available space. Two comparisons on a short list, at which point the remainder of them are a simple comparison to get a () out, which ends up as a

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Andrew Molyneux
Steven Lembark wrote: Yes, becuase if you did it this way you'd get $end equal to the integer coult of the number of list arguments passed plus one for the end value. Notice the usage: my $string = commify 90, ', ', 'etc...', @names; D'oh! (slaps head). Serves me right for not reading your

Re: limit the list

2002-11-20 Thread badchoice
join ', ', grep{ ($b.=$_) !~ /.{91}/ || ?.? ($_ = 'etc.') } @names

Re: limit the list

2002-11-20 Thread Josh Goldberg
On Wed, 20 Nov 2002 [EMAIL PROTECTED] wrote: join ', ', grep{ ($b.=$_) !~ /.{91}/ || ?.? ($_ = 'etc.') } @names that didn't work in my test, but it gave me an idea with map. I know, I used goto, but when I try to break from the BLOCK it says i'm not really in a block inside map, even when I

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Josh Goldberg [EMAIL PROTECTED] [2002-11-20 19:20]: map{$i++$lim?push @n,$_:$i!=$lim?{push @n,'etc.' and goto FOO}:''}@names; Sigh. map in void context and goto where a for would have done. And it doesn't even conform to the specs, you were asked to provide a string with less than 90

Re: limit the list

2002-11-20 Thread Steven Lembark
-- Josh Goldberg [EMAIL PROTECTED] On Wed, 20 Nov 2002 [EMAIL PROTECTED] wrote: join ', ', grep{ ($b.=$_) !~ /.{91}/ || ?.? ($_ = 'etc.') } @names that didn't work in my test, but it gave me an idea with map. I know, I used goto, but when I try to break from the BLOCK it says i'm not

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Philip Newton
On Wed, 20 Nov 2002 10:35:11 -0600, [EMAIL PROTECTED] (Steven Lembark) wrote: -- Andrew Molyneux [EMAIL PROTECTED] I'd probably do: my ($max, $sep, $end) = @_; Yes, becuase if you did it this way you'd get $end equal to the integer coult of the number of list arguments passed plus one

Re: limit the list

2002-11-20 Thread badchoice
On Wed, 20 Nov 2002 12:30:46 -0600 Steven Lembark [EMAIL PROTECTED] wrote: -- [EMAIL PROTECTED] join ', ', grep{ ($b.=$_) !~ /.{91}/ || ?.? ($_ = 'etc.') } @names Problem: the length does not include separators. This will lead to over-length strings. ack. assuming: @names 1;

Re: limit the list

2002-11-20 Thread Steven Lembark
-- [EMAIL PROTECTED] On Wed, 20 Nov 2002 12:30:46 -0600 Steven Lembark [EMAIL PROTECTED] wrote: -- [EMAIL PROTECTED] join ', ', grep{ ($b.=$_) !~ /.{91}/ || ?.? ($_ = 'etc.') } @names Problem: the length does not include separators. This will lead to over-length strings. ack. This

Re: limit the list

2002-11-20 Thread Jonathan E. Paton
Hi all, Lets get back to the original question: --- Selector, Lev Y [EMAIL PROTECTED] wrote: Folks, Simple question: Is there a more elegant way to express this: an array of names is converted into a comma-separated list. if the list gets to long - limit it and add , etc. at the end.

RE: limit the list

2002-11-20 Thread Alistair . McGlinchy
Not elegant but it is fun. $str= (grep {90 length} ( (map {join , , @names[0..$_], etc.} 0..$#names), join(, ,@names) ))[-1]; --- Registered Office: Marks Spencer p.l.c

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Steven Lembark [EMAIL PROTECTED] [2002-11-20 20:51]: Look up what happens to arrays in a scalar context. my ( $a, $b, $c ) = qw( foo bar bletch blort bim bam blort ); what do yo get for $c? 'bletch' - and that's not an array there. -- Regards, Aristotle

RE: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Alistair . McGlinchy
-Original Message- From: Steven Lembark [mailto:[EMAIL PROTECTED]] -- Philip Newton [EMAIL PROTECTED] On Wed, 20 Nov 2002 10:35:11 -0600, [EMAIL PROTECTED] (Steven Lembark) wrote: -- Andrew Molyneux [EMAIL PROTECTED] I'd probably do: my ($max, $sep, $end) = @_; Yes,

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Jonathan E. Paton [EMAIL PROTECTED] [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

Re: AW: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Vladi Belperchinov-Shabanski
On Wed, 20 Nov 2002 13:34:40 - Pense, Joachim [EMAIL PROTECTED] wrote: Bart Lateur [mailto:[EMAIL PROTECTED]] wrote: (Mittwoch, 20. November 2002 11:43) On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my ( $max, $sep, $end ) = ( shift, shift, shift );

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Peter Scott
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Abigail) writes: On Wed, Nov 20, 2002 at 11:42:43AM +0100, Bart Lateur wrote: On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my ( $max, $sep, $end ) = ( shift, shift, shift ); ... } Wow! Hold it! Am I

Re: limit the list

2002-11-20 Thread Jonathan E. Paton
--- A. Pagaltzis [EMAIL PROTECTED] wrote: * Jonathan E. Paton [EMAIL PROTECTED] [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

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Andrew Molyneux [EMAIL PROTECTED] [2002-11-20 18:25]: A. Pagaltzis wrote: Enter splice. my ($max, $sep, $end) = splice @_, 0, 3; That has brevity, certainly, but for legibility, I think I prefer Steven's original (shift,shift,shift) Really? I find the splice version a lot easier on

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Steven Lembark
-- Peter Scott [EMAIL PROTECTED] In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Abigail) writes: On Wed, Nov 20, 2002 at 11:42:43AM +0100, Bart Lateur wrote: On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my ( $max, $sep, $end ) = ( shift, shift, shift ); ...

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Steven Lembark
-- Philip Newton [EMAIL PROTECTED] hat happens when you do @a = qw( foo bar bletch blort bim bam blort ); my ( $a, $b, $c ) = @a; ? Obviously a better example. Point is that $c is one item on the list, but $a, $b, and $c are still on the list. Given that the original code used the

Re: limit the list

2002-11-20 Thread Jonathan E. Paton
join ', ', @array[0 .. $bound], @array $bound ? 'etc' : (); No, it's not. In my way the effects on the array are permanent, although that's probably not useful in this instance Point taken. @array = @array[0 .. $bound], @array $bound ? 'etc' : (); join ', ', @array; :-)

Re: limit the list

2002-11-20 Thread Steven Lembark
The text said: Is there a more elegant way to express this: an array of names is converted into a comma-separated list. if the list gets to long - limit it and add , etc. at the end. but, the code said: $str = join ', ', @names; if (length($str)90) {

Re: AW: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Steven Lembark
-- Vladi Belperchinov-Shabanski [EMAIL PROTECTED] On Wed, 20 Nov 2002 13:34:40 - Pense, Joachim [EMAIL PROTECTED] wrote: Bart Lateur [mailto:[EMAIL PROTECTED]] wrote: (Mittwoch, 20. November 2002 11:43) On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote: sub commify { my (

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Paul Johnson
On Wed, Nov 20, 2002 at 08:46:25PM -, Peter Scott wrote: [EMAIL PROTECTED] (Steven Lembark) writes: -- Peter Scott [EMAIL PROTECTED] In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Abigail) writes: On Wed, Nov 20, 2002 at 11:42:43AM +0100, Bart Lateur wrote: On Wed, 20 Nov 2002

Re: limit the list

2002-11-20 Thread Dave Arnold
In message [EMAIL PROTECTED] Selector, Lev Y [EMAIL PROTECTED] wrote: Folks, Simple question: Is there a more elegant way to express this: an array of names is converted into a comma-separated list. if the list gets to long - limit it and add , etc. at the end. $str

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* 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