106 my @tempArray = @{$this->{'entityhash'}->{$entity}}; 107 for (my $index; $index < @tempArray; $index++) 108 { 109 if ($tempArray[$index] == $entityId) 110 { 111 splice(@{$this->{'entityhash'}->{$entity}}, $index +, 1); 112 } 113 } 137 my @tempArray = @{$this->{'entityhash'}->{$entity}}; 138 for (my $index; $index < @tempArray; $index++) 139 { 140 if ($tempArray[$index] == $entityId) 141 { 142 splice(@{$this->{'entityhash'}->{$entity}}, $index +, 1); 143 } 144 }
This code will only work correctly if there is only one element of the array that matches $entityId. You should put last; after the splice so that you don't try to remove more than one element.
If you have mutliple elements that need to be removed then using grep would be simpler:
@{ $this->{ entityhash }{ $entity } } = grep $_ != $entityId, @{ $this +->{ entityhash }{ $entity } };
On your 'hash' keys you are assigning hashes so shouldn't you also assign arrays to the 'array' keys?6 # Constructor 7 sub new 8 { 9 my $self = {}; 10 $self->{'entityhash'} = {}; 11 $self->{'entityarray'} = (); 12 $self->{'relationshiphash'} = {}; 13 $self->{'predicatearray'} = (); 14 $self->{'entitypool'} = (); 15 bless($self, 'AssocDB'); 16 }
# Constructor sub new { my $self = {}; $self->{'entityhash'} = {}; $self->{'entityarray'} = []; $self->{'relationshiphash'} = {}; $self->{'predicatearray'} = []; $self->{'entitypool'} = []; bless($self, 'AssocDB'); }
Perl uses autovivification so these lines are unnecessary and don't actually do what you seem to think they do.28 if (!exists($this->{'entityhash'}->{$entity})) 29 { 30 $this->{'entityhash'}->{$entity} = (); 31 } 38 if (!exists($this->{'entityhash'}->{$entity})) 39 { 40 $this->{'entityhash'}->{$entity} = (); 41 } 57 if (!exists($this->{'entityhash'}->{$entity})) 58 { 59 $this->{'entityhash'}->{$entity} = (); 60 } 68 if (!exists($this->{'entityhash'}->{$entity})) 69 { 70 $this->{'entityhash'}->{$entity} = (); 71 }
In reply to Re: Associative Database
by jwkrahn
in thread Associative Database
by blockcipher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |