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
    Dear monks, Please help me, if I want to remove data from multidimensional array. What if in the above example I just want to remove 1 entity from 2nd dimension. Eg : $aoa11 = 161509, is to be removed. thus if I try printing $aoa not it should only give ( CR 111847 190251 190252 )