in reply to Removing array elements

If deletion is so often, you probably should use hash instead of array. Here is some benchmark:

use strict; use warnings; use Benchmark("timethese"); my $array; for (1 .. 100_000) { push @$array, $_; } my $hash; for (1 .. 100_000) { $hash->{$_} = 1; } timethese(1, {'array' => sub {s1($array)}, 'hash' => sub{s2($hash)}}); sub s1 { my $array = shift; for (my $i = 100_000; $i > 0; $i --) { splice(@$array, int(rand($i)), 1); } } sub s2 { my $hash = shift; for (my $i = 100_000; $i > 0; $i --) { delete($hash->{int(rand($i))}); } }

Result on my XP is:

Benchmark: timing 1 iterations of array, hash... array: 8 wallclock secs ( 7.38 usr + 0.00 sys = 7.38 CPU) @ 0 +.14/s (n=1 ) (warning: too few iterations for a reliable count) hash: 0 wallclock secs ( 0.20 usr + 0.00 sys = 0.20 CPU) @ 4 +.93/s (n=1 ) (warning: too few iterations for a reliable count) C:\Perl\bin>perl -w math1.pl Benchmark: timing 1 iterations of array, hash... array: 8 wallclock secs ( 7.44 usr + 0.00 sys = 7.44 CPU) @ 0 +.13/s (n=1 ) (warning: too few iterations for a reliable count) hash: 0 wallclock secs ( 0.25 usr + 0.00 sys = 0.25 CPU) @ 4 +.00/s (n=1 ) (warning: too few iterations for a reliable count)