in reply to inserting elements in an array

There are two easy ways to do this. One is splice, as others have shown:

splice @fred, 2, 0, "hello";
the other is
@fred[2 .. @fred] = ("hello", @fred[2 .. @fred - 1]);
which has the advantage that you don't have to remember the way splice interprets its arguments.

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
    Huh, I've always thought that splice has pretty intuitive arguments. Would you have expected some different order?