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

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?


Comment on Re: Storing Info
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-07-23 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (139 votes), past polls