kgherman has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use splice to obtain an array that is the subset of another array but something isn't working. The following code, returns a value of 67 for the pair of arguments of splice (1, -3) rather than the array 34 67. Why?
#!/usr/bin/perl my @a = (99999, 34,67,976,432,99999); my $length = scalar(@a); for ($counter = 0; $counter<=$length; $counter++){ my $max = max(-3 + $counter, 1); print "$max\n"; my $second_counter = -($length - $counter); print "$second_counter\n"; my @worker = splice @a, $max, $second_counter; print "@worker\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sub-setting an Array
by 1nickt (Canon) on Sep 05, 2015 at 00:02 UTC | |
by Anonymous Monk on Sep 05, 2015 at 00:25 UTC | |
by 1nickt (Canon) on Sep 05, 2015 at 00:40 UTC | |
by Anonymous Monk on Sep 05, 2015 at 00:45 UTC | |
by AnomalousMonk (Archbishop) on Sep 05, 2015 at 03:23 UTC | |
by 1nickt (Canon) on Sep 05, 2015 at 01:05 UTC | |
| |
by Anonymous Monk on Sep 05, 2015 at 00:43 UTC | |
|
Re: Sub-setting an Array
by stevieb (Canon) on Sep 04, 2015 at 23:59 UTC | |
by Anonymous Monk on Sep 05, 2015 at 00:28 UTC | |
by AnomalousMonk (Archbishop) on Sep 05, 2015 at 03:02 UTC | |
|
Re: Sub-setting an Array
by Laurent_R (Canon) on Sep 05, 2015 at 08:48 UTC |