in reply to Split() first 3 elements of @array
Select the first 3 elements of an array as:
@array[0..2]
exerting care in case there are less than 3 elements.
use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump); my @RouterOutput = split /\n/, << 'END'; 1 AAAA BBBB CCCC 2 AAAA BBBB CCCC 3 AAAA BBBB CCCC 4 AAAA BBBB CCCC END for(@RouterOutput[0..2]) {say "@{[split]}[0,3,2,1]" if $_; }
Produces
1 CCCC BBBB AAAA 2 CCCC BBBB AAAA 3 CCCC BBBB AAAA
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Split() first 3 elements of @array
by hmb104 (Sexton) on Aug 28, 2012 at 19:10 UTC | |
by ig (Vicar) on Aug 28, 2012 at 20:40 UTC | |
by Kenosis (Priest) on Aug 28, 2012 at 20:48 UTC | |
by Kenosis (Priest) on Aug 28, 2012 at 19:42 UTC |
In Section
Seekers of Perl Wisdom