in reply to Re: Spliting array into nested sequential arrays
in thread Spliting array into nested sequential arrays

That is correct. Sorry there was a typo in the square bracket entity. Fixed it now.
  • Comment on Re^2: Spliting array into nested sequential arrays

Replies are listed 'Best First'.
Re^3: Spliting array into nested sequential arrays
by boftx (Deacon) on Oct 29, 2014 at 01:21 UTC

    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.
      My assumption was that I no longer had @array1 to work with and had to create the final sorted array from @newarray.

        Never assume what is required. Trust me. Ask and ask again and preferably get the specs in writing. If the spec is ambiguous, then I assure you that you will have to either do it over or have people call your code naive at best. :)

        You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.