in reply to Splice a multidimensional array
Splicing an array from an array of arrays (a 2-D array) is no different than splicing an element from an array of scalars (a 1-D array). That's because an AoA is really just an array of array references, and references are stored as scalars. For example:
use strict; use warnings; use Data::Dumper; my @aoa = ( [ qw( CR 161508 111847 151085 190251 ) ], [ qw( CR 161509 111847 190251 190252 ) ], [ qw( CR 161510 111847 190252 190150 ) ], [ qw( CR 161511 111847 190150 190153 ) ] ); print "orig aoa: @aoa\n"; print Dumper( \@aoa ), "\n"; my @spliced = splice( @aoa, 1, 1 ); print "spliced aoa: @aoa\n"; print Dumper( \@aoa ), "\n"; print "spliced: @spliced\n"; print Dumper( \@spliced ), "\n";
The output from this code is as follows:
orig aoa: ARRAY(0x183f064) ARRAY(0x18350e8) ARRAY(0x1835190) ARRAY(0x1 +835238) $VAR1 = [ [ 'CR', '161508', '111847', '151085', '190251' ], [ 'CR', '161509', '111847', '190251', '190252' ], [ 'CR', '161510', '111847', '190252', '190150' ], [ 'CR', '161511', '111847', '190150', '190153' ] ]; spliced aoa: ARRAY(0x183f064) ARRAY(0x1835190) ARRAY(0x1835238) $VAR1 = [ [ 'CR', '161508', '111847', '151085', '190251' ], [ 'CR', '161510', '111847', '190252', '190150' ], [ 'CR', '161511', '111847', '190150', '190153' ] ]; spliced: ARRAY(0x18350e8) $VAR1 = [ [ 'CR', '161509', '111847', '190251', '190252' ] ];
HTH
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Splice a multidimensional array
by Anonymous Monk on Apr 22, 2015 at 09:50 UTC |