in reply to Re^2: Spliting array into nested sequential arrays
in thread Spliting array into nested sequential arrays
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__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Spliting array into nested sequential arrays
by Hameed (Acolyte) on Oct 29, 2014 at 01:34 UTC | |
by boftx (Deacon) on Oct 29, 2014 at 02:17 UTC | |
by Hameed (Acolyte) on Oct 29, 2014 at 03:38 UTC |