in reply to Extracting numbers from arrays
This solves the problem by storing the first and last index of each number in %f and %l. Then you can get the whole slice between both numbers.@a=qw(1 2 3 4 5 6 7 8 9 2 3 1 4 5 6 7 8 9 1 4); $first=3; $last=1; @l{@a}=0..$#a; @f{reverse @a}=reverse 0..$#a; print join ' ',@a[$f{$first}..$l{$last}],"\n";
Maybe you want to use
to get the complet rest of the array if the last number isn't behind the first.@a[$f{$first}..$l{$last}>=$f{$first}?$l{$last}:$#a]
|
|---|