in reply to How might I handle a special tree?
Using splice to replace a subset of the top level array with an anonymous array holding the values replaced is fairly easy:
@sorted = 0 .. 9;; splice @sorted, 1, 8, [ @sorted[ 1 .. 8 ] ];; pp @sorted;; (0, [1, 2, 3, 4, 5, 6, 7, 8], 9)
However, if you need to perform that same operation on one of the nested anonymous arrays, it gets somewhat more complicated:
splice @{ $sorted[1] }, 1, 6, [ @{ $sorted[ 1] }[ 1 .. 6 ] ];; pp @sorted;; (0, [1, [2, 3, 4, 5, 6, 7], 8], 9)
And if you need to go deeper still, it starts to get quite unweildy:
splice @{ $sorted[1][1] }, 1, 4, [ @{ $sorted[1][1] }[ 1 .. 4 ] ];; pp @sorted;; (0, [1, [2, [3, 4, 5, 6], 7], 8], 9)
|
|---|