in reply to Re: insert element into an array
in thread insert element into an array

Thanks for your (and Dave's) answer.
You mention you'd rather use unshift, is this for any particular reason (like performance maybe) ?
As a newbie to Perl I'd like to understand which is the preferred method. Or is it just down to personal choice ?
In this particular case I wouldn't expect the matrix to be more than about 100 records by the way.

Replies are listed 'Best First'.
unshift vs splice
by ikegami (Patriarch) on Nov 16, 2004 at 17:33 UTC

    Something leads me to believe performance is the same with both (but Benchmark if you want to be sure). The reason would be readability. splice(@a, 0, 0, $val); is not even closely as readable as unshift(@$rc, $val);.

    By the way, Perl is very efficient at adding to and removing from both the front and the end of arrays. That includes shift, unshift, push, pop, their splice equivalents, and probably $a[@a] = $val.