Without knowing the exact question posed, you did not need to push stuff onto @array3. All you had to do was this for that: my @array3 = sort(@array1);

As for generating the sub-arrays, give me a few minutes and I'll have something different than using indexes.

Update: working code.

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; $Data::Dumper::Indent = 1; my @array1 = (1,2,3,4,5,6,7,8,3,5,6,3,8,1,7,8); my @array3 = sort(@array1); my @subarrays = ( [] ); my $last = 0; for ( @array1 ) { push(@subarrays, []) if $_ < $last; push(@{$subarrays[-1]},$_); $last = $_; } print Dumper(\@array1); print Dumper(\@subarrays); print Dumper(\@array3); exit; __END__
You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

In reply to Re^3: Spliting array into nested sequential arrays by boftx
in thread Spliting array into nested sequential arrays by Hameed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.