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

In reply to Re: Accessing (deleting) array elements in a hash of arrays by sflitman
in thread Accessing (deleting) array elements in a hash of arrays by onslaught

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.