in reply to Re^2: removing elements in array in perl
in thread removing elements in array in perl
Ah - I was confused about your double usage of numbers as array elements and array indices.
To me, it feels as if you have a number $n and want to remove $n elements from @A1 and put them into A2:
use strict; use Data::Dumper; my @A1 = qw(a b c d e f g); my $n = 2; my @A2 = splice @A1, @A1-$n, $n; print Dumper [\@A1, \@A2]; __END__ $VAR1 = [ [ 'a', 'b', 'c', 'd', 'e' ], [ 'f', 'g' ] ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: removing elements in array in perl
by AnomalousMonk (Archbishop) on Nov 23, 2016 at 16:42 UTC | |
|
Re^4: removing elements in array in perl
by t-rex (Scribe) on Nov 23, 2016 at 09:50 UTC |