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
-- 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 .=
* 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
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
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
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
--- 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
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
-- 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,
-- 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
-- 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
-- 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
* 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
* 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
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
join ', ', grep{ ($b.=$_) !~ /.{91}/ || ?.? ($_ = 'etc.') } @names
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
* 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
-- 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
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
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;
-- [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
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.
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
* 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
-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,
* 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
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 );
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
--- 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
* 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
-- 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 );
...
-- 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
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;
:-)
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) {
-- 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 (
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
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
* 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
39 matches
Mail list logo