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 } };
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 }
On your 'hash' keys you are assigning hashes so shouldn't you also assign arrays to the 'array' keys?
# Constructor sub new { my $self = {}; $self->{'entityhash'} = {}; $self->{'entityarray'} = []; $self->{'relationshiphash'} = {}; $self->{'predicatearray'} = []; $self->{'entitypool'} = []; bless($self, 'AssocDB'); }
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 }
Perl uses autovivification so these lines are unnecessary and don't actually do what you seem to think they do.

In reply to Re: Associative Database by jwkrahn
in thread Associative Database by blockcipher

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.