in reply to Sub-setting an Array
Hi kgherman,
The following code, returns a value of 67 . . .
This code doesn't compile. You should always use strict; and use warnings;, even in example code, then you won't forget to include something like the package that holds your max() ...
In order to get the results you want from the array you have, you need:
. . . I'm not sure what the rest of your code is for; please feel free to explain what you are really trying to do. Maybe you were trying to do something like this?splice(@array,1,2);
#!/usr/bin/perl use strict; use warnings; my @array = ( 99999, 34, 67, 976, 432, 99999 ); my $elements = @array; for ( my $offset = 0; $offset < $elements; $offset++ ) { for ( my $length = 0; $length <= $elements; $length++ ) { my @to_splice = @array; my @spliced = splice @to_splice, $offset, $length; print "splice(\@array, $offset, $length) : @spliced\n"; } }
Upate: added example
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sub-setting an Array
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 01:17 UTC | |
| |
by Anonymous Monk on Sep 05, 2015 at 00:43 UTC |