Hi listendohg,
I see that you figured out a solution. Here's a way that you might find simpler using array slices:
Output:#/usr/bin/perl use strict; use warnings; use feature 'say'; my @x = ( 1 .. 100 ); my @y = @x[ 0 .. 9 ]; my @z = @x[ -10 .. -1 ]; say join ',', @y; say join ',', reverse @z; __END__
If you don't know how many elements there are in your array:1,2,3,4,5,6,7,8,9,10 100,99,98,97,96,95,94,93,92,91
my @y = @x[ 0 .. 9 ]; my @z = @x[ $#x-9 .. $#x ];
Note that unlike in your solution which makes new lists, changing the values in @y or @z will change the original array @x.
Hope this helps!
Edit: add example without specified indices.
In reply to Re: I want to print a limited subsection of certain outputs?
by 1nickt
in thread I want to print a limited subsection of certain outputs?
by listendohg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |