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)

In reply to Re: Removing array elements by pg
in thread Removing array elements by sandrider

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.