in reply to Accessing (deleting) array elements in a hash of arrays

I think the problem is where you use ${...}$index. Try accessing array elements in hash of arrays as: $harry{$phash{$k}}->[$bcount] The other problem is I don't think you can call delete on array elements like that, at least not in Perl 5.8x. The docs say all you get is undef at that position and the later elements don't shift down, you need splice for that. I think I'd probably approach this general problem differently, using grep.
#!/usr/bin/perl use strict; use Data::Dumper; my %hashOfArrays=( a=>[1,2,3], b=>[4,5,6], c=>[7,8,9] ); my %toDelete=( a=>2, b=>6, c=>8 ); for my $array (keys %hashOfArrays) { if ($toDelete{$array}) { $hashOfArrays{$array}=[ grep { $_ != $toDelete{$array} } @{$hashOfArrays{$array}} ]; } } print Dumper(\%hashOfArrays); # prints $VAR1 = { # 'c' => [ # 7, # 9 # ], # 'a' => [ # 1, # 3 # ], # 'b' => [ # 4, # 5 # ] # }; exit;
I think this is what you're describing. A hash of arrays contains data which you may wish to selectively delete by specifying which array in the hash, and which element to delete. This code only allows one element at a time to be specified per array, but it wouldn't be hard to support multiple elements to be deleted if needed. Rather than use delete, I create a new anonymous array reference with [ EXPR ] and the array itself is made by grep EXPR ARRAY which converts the original array into a array of elements which do not equal the element to delete. Hope that helps. SSF