<snip>
use strict;
use warnings;

my @list = qw(0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1);
my @out;

@out = grep($_ != 0, @list);

foreach (@out){ print $_, "\n"; }
</snip>


-----Original Message-----
From: Michael Rauh [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 05, 2002 4:40 PM
To: Beginners, Perl
Subject: performance: pop? shift? or another way?


hi,

say i have an unsorted (large) list of, e.g., 0's and 1's:

@list = (0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, ...)

i now want to remove all the zeros, using the fastest way possible. how
would U do that?

i thought of sorting the zeros the left (or right) and then shift (or
pop) all zeros. or perhaps to first find the offset and then do a single
splice.

but perhaps there's another way? performance is most important here.
suggestions welcome.

greetings
michael

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to