in reply to inserting elements in an array
There are two easy ways to do this. One is splice, as others have shown:
the other issplice @fred, 2, 0, "hello";
which has the advantage that you don't have to remember the way splice interprets its arguments.@fred[2 .. @fred] = ("hello", @fred[2 .. @fred - 1]);
Update: D'oh, there's one more way I've forgot, although I've done something similar in Re: finding top 10 largest files:
@fred = (@fred[0 .. 2 - 1], "hello", @fred[2 .. @fred - 1]);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: inserting elements in an array
by ysth (Canon) on Feb 03, 2005 at 23:30 UTC |