in reply to insert element into array so that don't overwrite data at that position?
use splice
my @array = (0..7); splice @array, 4, 0, ('inserted-array'); print "@array\n";
Note: the other array operators (push, pop, shift, and unshift) can all be done with splice as well:
# push @array, @others; splice @array, @array, 0, @others; # my $element = pop @array my $element = splice @array, $#array, 1; # my $element = shift @array my $element = splice @array, 0, 1; # unshift @array, @others splice @array, 0, 0, @others;
Update: Fixed slight bug in push and pop equivalents. Ty AnomalousMonk
|
|---|