in reply to Spliting array into nested sequential arrays

In the first case, the code is naive in many a few ways, not the least of which, it gets the output wrong -- not including the final sequence of the input. In the second case, it could all be combined into a single pass as below, but it is correct to call the complexity O(n), it will scale linearly with the number of elements.

my @array3 = sort map {@$_} @newarray;

Update: I see you fixed the desired output, but the code still gets it wrong.

Update2: My comment here about complexity ignores sort, as requested in the question.

Replies are listed 'Best First'.
Re^2: Spliting array into nested sequential arrays
by GrandFather (Saint) on Oct 29, 2014 at 01:42 UTC
    but it is correct to call the complexity O(n), it will scale linearly with the number of elements

    Actually, probably not true. As far as I can tell @array3 = sort @array3; is O(N*log N) so it's unlikely the overall code is better than that.

    Perl is the programming world's equivalent of English
Re^2: Spliting array into nested sequential arrays
by Hameed (Acolyte) on Oct 29, 2014 at 01:44 UTC
    Of course. I had another line to push the last set. Missed it in here. So how would you tackle the fist question.

    I also thought about recursively splicing but I am not sure whether it would improve.

    I did not think of using map for the 2nd part. Very neat indead! Thank you.