in reply to adding to the middle of a array
Hi,
Obviously, the one you gave is 'a way' to do it... but there is more than one. The following is the one I use:
my @a = (1,2,3,4,5,6,7,8,9); my $pos = 3; my $new_elem = 100; $" = ", "; print "Before: (@a)\n"; @a = (@a[0..$pos-1],$new_elem,@a[$pos..$#a]); print "After: (@a)\n";
I'm sorry that I haven't the time now to benchmark these solutions...
I hope this serves to help you.
Cheers
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: adding to the middle of a array
by htoug (Deacon) on Feb 13, 2003 at 11:33 UTC | |
by TheHobbit (Pilgrim) on Feb 13, 2003 at 11:40 UTC | |
by Anonymous Monk on Feb 14, 2003 at 17:56 UTC |