Every time push is forced to allocate more memory, it needs to copy the entire array. This can be avoided by preallocating enough memory.
my $count = @array; $#array = $count*2 - 1; for (1 .. $count) { push @array, $value if ($value = shift @array) !~ /^\#/ }
In terms of scalability,
In reply to Re: Efficient array element deletion
by ikegami
in thread Efficient array element deletion
by kennethk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |