I need to process a large amount of data in arrays with Perl. At certain points, I will need to insert the values of a second array within a primary array. I have seen that splice should normally be the way to go. However, after having researched a bit, I have seen that this function is memory intensive and over time could cause a serious performance issue.
Here is basically what I am needing to do -
# two arrays
@primary = [1, 2, 3, 4, 5, 6, 7, 8, 9];
@second = [a, b, c, d e];
Now insert the content of @second into @primary at offset 4 to obtain -
@primary = [1, 2, 3, 4, a, b, c, d, e, 5, 6, 7, 8, 9];
Would using linked lists be the most efficient way to go when I have to handle a primary array which holds more than 2000 elements ?
Note: can anyone confirm that this is the correct way to do it
$Tail = splice($primary, 4);
push(@primary, @second, $Tail);
?
splice @primary, 4, 0, @second;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With