On Fri, 7 Jul 2000, Kevin Hoffman wrote:

> Hi,
> 
> I tried using the VMS::IndexedFile on a key that allowed duplicates, but I get 
>strange results.  The keys function returned the wrong data, and the each function 
>never returns undef so an infinite loop ensues.
> 
> What would really be cool, if you could use some syntax like this:
> 
> @subset = @hash{ 'ABC' };
> 
> Which when used on a dup key, would return the set of records matching 'ABC'.  This 
>is pretty much a long shot, since it would require the tie FETCH method to know it 
>was in array context.  I've tried wantarray in a FETCH routine and it doesn't work.
> 
> Another idea might be to include the key criteria on the TIEHASH method.  That way 
>you always tie to a subset of the data instead of the entire table.  Something like 
>the following which would tie the hash to only those rows matching duplicate key 
>value "ABC"
> 
> $mydupkey = 2;
> tie( %h, 'VMS::IndexedFile', [ 'filespec' => "TEST.DAT", 'key' => $mydupkey, 
>'keyval' => "ABC", 'keylen' => 3 ] );
> 
> 
> Maybe the best yet is to provide a couple of methods for accessing data through 
>duplicate keys.  Since duplicate keys really don't fit the HASH paradigm, it would 
>probably be better to just provide a couple of methods that allowed you to access 
>multiple rows.  Of course, you would probably have to disable FETCH, STORE, DELETE, 
>FIRSTKEY, NEXTKEY since they don't really make sense.  Something like the following 
>which would also access those rows matching duplicate key value "ABC"
> 
> $rv = $obj->First( "ABC", 3, $ctxt );
> while( $rv )
> {
>     $rv = $obj->Next("ABC",3, $ctxt );
> }
> 
> 
> thanks for listening...
> Kevin Hoffman
> 

Yes by its very nature hashing does not allow for duplicates.
However, you might be able to get away with one of the DBM serializers
such as Gurusamy Sarathy's MLDBM available from CPAN (I am not sure
if it builds on VMS, but Data::Dumper sure does and at least
SDBM_File do so your part of the way there).

By the way there is a pretty good discussion of various object
serialization techniques to use in conjunction with DB files in
Aligator Descartes and Tim Bince's new "Perl DBI" book available
from O'Reilly and in many bookstores (online and offline).

HTH

Peter Prymmer





Reply via email to