David Wagner wrote:
>
> I have two hashes and each is made up of two keys. One has only a numeric
> value and the the second one has the detail. If I find out that I have right
> situation, I change the numeric value in the first hash. I have done data
> dumper where I create the hash and as I update the hash value and everything
> looks like I would expect it.
>
> So I decided to delete the keys from hash 1 and 2 if the numeric value on hash
> 1 is not what I want. I print this out with Data::Dumper and I have hash setup
> I am not understanding.
>
> Here is a portion of Data::Dumper:
>
>   'VNM' => {
>     'LVR' => 9,
>     'NVN' => 9
>   },
>   'BKF' => {
>     'FTV' => 9,
>     'SVX' => 1,
>     'SYO' => 9,
>     'BMT' => 9
>   },
>
>   but after I get done,it would look like this:
>
>   'VNM' => {},
>   'BKF' => {
>     'SVX' => 1,
>   },
>
> Here is the code which is doing the delete. I am getting the right output I
> need to work with, but I don't understand the {} entries:
>
> foreach $MyPrtKeya ( keys %{$MyVPEPRelationships} ) {
>   foreach $MyPrtKeyb ( keys %{$MyVPEPRelationships->{$MyPrtKeya}} ) {
>     next if ($MyVPEPRelationships->{$MyPrtKeya}{$MyPrtKeyb} == 1 );
>     delete($MyVPEPMTs->{$MyPrtKeya}{$MyPrtKeyb});
>     delete($MyVPEPRelationships->{$MyPrtKeya}{$MyPrtKeyb});
>   }
> }
>
> The code is run under strict and warnings and I get no warnings etc.
>
> If you have any problems or questions, please let me know.

I'm not clear what it is you don't understand David. You're deleting elements
from both the MTs and the Relationships hashes if the relationships hash value
isn't 1. Is it the 'VNM' => {} line you didn't expect? If you want the element
to disappear when the hash that its value refers to becomes empty then you will
have to code that in. Something like

foreach my $keya (keys %{$MyVPEPRelationships}) {

  foreach my $keyb (keys %{$MyVPEPRelationships->{$keya}}) {

    next if ($MyVPEPRelationships->{$keya}{$keyb} == 1);

    delete $MyVPEPMTs->{$keya}{$keyb};
    delete $MyVPEPMTs->{$keya} unless %{$MyVPEPMTs->{$keya}};

    delete $MyVPEPRelationships->{$keya}{$keyb};
    delete $MyVPEPRelationships->{$keya} unless 
%{$MyVPEPRelationships->{$keya}};
  }
}


HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to