
mhx
Enthusiast
Nov 8, 2001, 9:06 AM
Post #2 of 7
(2918 views)
|
|
Re: (ARRAYS) Open row, specific column search...
[In reply to]
|
Can't Post
|
|
Wow, I've read through your posts in the beginner's forum for 5 or 6 times and now I think I've got your point. So, you have a huge database, and need a random number that is not yet contained in the nth column of any row. If that is not what you want, skip the rest of my post and forgive me. You stated that you read the whole database into an array of arrays (rows and columns). Don't do that if you only need a single column, because it will eat up too much memory if the database grows. With your problem im mind, you should build a hash table directly while reading the database with the values in the column of interest as keys and whatever you like as value:
while( <DB> ) { $hash{(split /$separator/)[$column]} = 1; } Then, your random number loop should be:
$lower = $input->param('lbound'); $range = $input->param('ubound') - $input->param('lbound') + 1; do { $random = $lower + int rand $range } while exists $hash{$random}; Hope this helps. -- Marcus
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= ($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"
|