in reply to Linked lists as arrays: inserting values
This doesn't work for the edge cases (first and last element), but hey, that's what pop and friends are there for. Maybe you could write an email to the author of List::MoreUtils to provide an insert_at_index function?.sub insert_array_elem { my ($ra, $elem, $index) = @_; # insert $elem before $ra->[$index] my $idx = 0; insert_after { $idx++ == $index-1; } $elem => @{$ra}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Linked lists as arrays: inserting values
by radiantmatrix (Parson) on Sep 25, 2006 at 17:13 UTC | |
by holli (Abbot) on Sep 26, 2006 at 07:00 UTC |