Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have this Array of Array of Hashes (i think).
$VAR1 = [ [ 'IMG0001', [ { 'y' => 0, 'filename' => 'new value', 'x' => 0 }, { 'y' => 10, 'filename' => 'cel.jpg', 'x' => 10 } ] ], [ 'IMG0002', [ { 'y' => 0, 'filename' => 'batman.jpg', 'x' => 0 }, { 'y' => 10, 'filename' => 'robin.jpg', 'x' => 10 } ] ] ];
i need to splice / remove the part below.
{ 'y' => 10, 'filename' => 'robin.jpg', 'x' => 10 }
i have tried using splice but it says that i cannot use splice on an array slice. help!

Replies are listed 'Best First'.
Re: Array of Array or Hashes Splice
by JavaFan (Canon) on May 11, 2009 at 07:28 UTC
    #!/usr/bin/perl use strict; use warnings; use YAML; my $arr = [[IMG0001 => [{y => 0, filename => 'new value', x => 0,}, {y => 0, filename => 'cel.jpg', x => 10,},], ], [IMG0002 => [{y => 0, filename => 'batman.jpg', x => 0}, {y => 10, filename => 'robin.jpg', x => 10,},], ]]; splice @{$$arr[1][1]}, 1, 1; print Dump $arr; __END__ --- - - IMG0001 - - filename: new value x: 0 y: 0 - filename: cel.jpg x: 10 y: 0 - - IMG0002 - - filename: batman.jpg x: 0 y: 0
Re: Array of Array or Hashes Splice
by Anonymous Monk on May 11, 2009 at 07:33 UTC
    #!/usr/bin/perl -- $VAR1 = [ [ 'IMG0001', [ { 'y' => 0, 'filename' => 'new value', 'x' => 0 }, { 'y' => 10, 'filename' => 'cel.jpg', 'x' => 10 } ] ], [ 'IMG0002', [ { 'y' => 0, 'filename' => 'batman.jpg', 'x' => 0 }, { 'y' => 10, 'filename' => 'robin.jpg', 'x' => 10 } ] ] ]; print $VAR1->[1][1][1]{filename},$/; splice @{$VAR1->[1][1]}, 1; use Data::Dumper; print Dumper( $VAR1),$/; __END__ robin.jpg $VAR1 = [ [ 'IMG0001', [ { 'y' => 0, 'filename' => 'new value', 'x' => 0 }, { 'y' => 10, 'filename' => 'cel.jpg', 'x' => 10 } ] ], [ 'IMG0002', [ { 'y' => 0, 'filename' => 'batman.jpg', 'x' => 0 } ] ] ];
Re: Array of Array or Hashes Splice
by leslie (Pilgrim) on May 11, 2009 at 14:15 UTC
    Hi firend,
    You can do like this also,
    use strict; use warnings; use Data::Dumper; my $arr = [ [ IMG0001 => [ { y => 0, filename => 'new value', x => 0, }, { y => 0, filename => 'cel.jpg', x => 10, }, ], ], [ IMG0002 => [ { y => 0, filename => 'batman.jpg', x => 0 }, { y => 10, filename => 'robin.jpg', x => 10, }, ], ] ]; splice @{$arr->[1]->[1]}, 1, 1; print Dumper $arr;