View Single Post
Old 03-07-2006, 03:25 PM   #5 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
I think the approach you take sort of deoends on the structure of your data. If your data looks like this
Code:
identifier1	id1field1	id1field2	id1field3
identifier2	id2field1	id2field2	id2field3
then you can use associative arrays that key off of the identifier, and store the fields as an array in the other side of the the hash pairs e.g.
Code:
# %database{identifier1} => ('id1field1, id1field3, id1field3,);
@fields = ($field1, $field2, $field3);
$database{$identifier} = \@fields;
That way the identifier is basically the primary key (which must be unique) and looking up things based on that key is easy. Querying based other pieces of data means iterating through hash though.
Code:
@results;
foreach $record (keys(%database)) {
    foreach $field (@$database{$record}) {
        if( $field eq $myquery) {
            push(@results, $record);
        }
    }
}
Does that help? If I've been unclear or you need anything else, just ask.
__________________
Stop intellectual property from infringing on me

Last edited by teknomage1; 03-07-2006 at 04:14 PM.
teknomage1 is offline   Reply With Quote