Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Storing Info

by demerphq (Chancellor)
on Jan 21, 2002 at 14:43 UTC ( #140365=note: print w/replies, xml ) Need Help??

in reply to Storing Info

Id probably do something like
create table friends ( friend_id numeric(8) identity, first_name varchar(32) not null, last_name varchar(32) not null, hair_color varchar(6) not null, constraint PK_FRIENDS primary key (friend_id) ) go create unique index ui_no_dupes on friends ( first_name ASC, last_name ASC, hair_color ASC ) go create index i_first_name on friends (first_name ASC) go create index i_last_name on friends (last_name ASC) go create index i_hair_color on friends (hair_color ASC) go
And then I'd use DBI something like this
my $connstr="dbi::SomeDB"; my $dbh=DBI->connect($connstr,$user,$password) or die "Can't open connection to $connstr"; my $array = $dbh->selectall_arrayref(<<SQL) || die $dbh->errstr; select first_name, last_name, hair_color from friends where first_name is like "j%" and hair_color="brown" SQL print join"\n",map { join ",",@$_ } @$array;
Of course thats just me. YMMV. Oh, yeah, if it were a serious table then id put the hair color as a foreign key into a seperate table of allowed colors, for integrity purposes.

BTW, I dont really understand what the d++ is for. I would have thought you would want to iterate over your list and check each one to see if it matched your requirements. If it does then push them into a different array. Actually isnt that what grep does?

Of course you might optimise it by creating a hash of hair colors, each containing an array of elements that so match. That way you wouldnt have to search the whole list. Of course hashes arent really meant as indexes so you might want to stick with database technology, after all its to answer these types of questions that SQL and DB's were invented.

Yves / DeMerphq
When to use Prototypes?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://140365]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2019-10-18 04:03 GMT
Find Nodes?
    Voting Booth?