Re: Programming Question
Rhesa Rozendaal <[email protected]>
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <[email protected]> |
Douglas S. Davis wrote:
> Hi,
>
> My problem (and I am sure it must be simple to do) is that I can't
> figure out how to compare the list of possible numbers (100 - 499)
> with the list of already in use numbers returned by my query. I've
> tried various loops and while statements all to no avail. Usually
> what I get is that for *each* number in the result set of my query,
> it prints out all of the numbers from 100 - 499.
Sounds like you could use a sieve, just like the famous Sieve of Eratosthenes.
> Can anyone point me in the right direction. So in other words,
> when I do my fetchrow() on the MySQL table, how can I take the
> results and compare them to the 100 - 499 set of numbers.
It roughly goes like this:
# create a hash containing all numbers
@sieve{100 .. 499} = (1)x399;
# loop over your "in use" numbers, and delete them from the hash
while( my ($n) = $sth->fetchrow ) {
delete $sieve{$n};
}
# what you have left is the available numbers
@available = sort keys %sieve;
HTH,
Rhesa
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/[email protected]