Hi,
I'm still wondering about compiling problems, but today's question is
totally different.
I'm creating a database which would contain many emails (that should be
unique). In that database would be 4-5 tables, and every one's primary
key should have a reference to 'the main table' which primary key is
email. But, emails can be very long, so having emails as part of
primary key is complete waste of time & space. So I want to assign UID
to every email. I gave a fixed length of 6 to every UID, and used this
simple way to generate it:
input is email as string
my $lett = substr($email, 0, 2);
my $num = fill_to_4_fields(0); #also truncates to len 4
my $sth = $dbh->prepare('SELECT COUNT(*) FROM email_table WHERE email =
?');
$sth->execute($lett.$num);
$cnt = 0;
while (scalar $sth->fetchrow_array()) {
if ($num = 9999) {
$ka = '';
$lett =~ s{([a-z0-9])$}{ $ka = $1; $ka =~ tr/0-9a-z/1-9ab-z0/;
$ka;}e;
$cnt++;
if ($cnt == 37**2) die('cannot create UID');
if ($cnt % 36 == 0) {
$lett =~ s{^([a-z0-9])}{ $ka = $1; $ka =~ tr/0-9a-z/1-9ab-z0/;
$ka;}e;
}
}
$num = fill_to_4_fields($num+1);
$sth->execute($lett.$num);
}
But this seems a little bit slow and not so elegant. And it fails after
37**2 * 10000 users that should be enough. Only pitfall is 37**2 *10000
requests to DB:(
Does anyone knows a better way to accomplish the same thing, and which
would be faster and more perlish?
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users