> > > I would like to remove elements from an array that are eq to > > > string '0' > > > The following does not work, can someone shed some light on > > > the proper > > > way to do this. > > > Thanks! > > > Dave G.
Here's an interesting benchmark comparing the splice, new list, and grep (grep is the winner): C:\tmp>perl ptest Rate splice newlist grep splice 55188/s -- -34% -37% newlist 84175/s 53% -- -4% grep 87642/s 59% 4% -- Code: use strict; use Benchmark qw/cmpthese/; cmpthese(100000, { 'grep' => \&sub_grep, 'splice' => \&sub_splice, 'newlist' => \&newlist }); sub sub_grep { my @bq = ( '0', 1, '0', '0', '0', '0', '0', '0', '0' ); @bq = grep { $_ ne '0' } @bq; } sub sub_splice { my @bq = ( '0', 1, '0', '0', '0', '0', '0', '0', '0' ); for (my $i = 0; $i < @bq; ++$i) { if ($bq[$i] eq '0') { splice @bq, $i, 1; redo; } } } sub newlist { my @bq = ( '0', 1, '0', '0', '0', '0', '0', '0', '0' ); my @new; for (@bq) { if ($_ ne '0') { push @new, $_; } } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]