kelan has asked for the wisdom of the Perl Monks concerning the following question:
But I have vague notions of blatant inefficiency, especially for large lists. I'm worried more about speed than memory use, but I don't know how this would compare to just explicitly moving one element at a time. Is it best just to do the old:$idx = 45; # pretend we've already found the insertion point @a[$idx+1 .. $#a+1] = @a[$idx .. $#a]; $a[$idx] = $newitem;
$idxmove = $#a; while ($idxmove >= $idx) { $a[$idxmove+1] = $a[$idxmove]; $idxmove--; } $a[$idx] = $newitem;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Shifting an Array
by Abigail-II (Bishop) on Aug 29, 2002 at 13:34 UTC | |
by kelan (Deacon) on Aug 30, 2002 at 13:00 UTC | |
by Abigail-II (Bishop) on Sep 04, 2002 at 09:56 UTC | |
|
Re: Shifting an Array
by hotshot (Prior) on Aug 29, 2002 at 13:36 UTC | |
|
Re: Shifting an Array
by LTjake (Prior) on Aug 29, 2002 at 13:43 UTC |