-----Original Message-----
From: Peter Guzis [mailto:[EMAIL PROTECTED]]
Sent: March 6, 2001 11:47 AM
To: '[EMAIL PROTECTED]'
Subject: RE: creating unique ID's


I just thought of another one:

use Time::HiRes qw( time );
my $id = time;
$id =~ tr/0123456789./ABCDEFGHIJK/;
print $id;

Peter Guzis
Web Administrator, Sr.
ENCAD, Inc.
email: [EMAIL PROTECTED]
www.encad.com

-----Original Message-----
From: Mauricio Lairet P. [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 05, 2001 12:22 PM
To: Nikola Knezevic; Perl Users Mailing List
Subject: Re: creating unique ID's


A posible solution is to retrieve the first 3 letters of the domain and add
the current date to it in format:

First-3-letters-of-the-mailMonthDayYearHourMinuteSecond

eg. If you add the email [EMAIL PROTECTED] on March/05/2001 at
01:05:32 PM it should create an ID like: bil35200113532

This works for me as it is really difficult (or imposible) that 2 emails
with the same first 3 letters will be created in the same and exact time.

Off course it would not be 6 characters long (it always would be 14 chars
long and if created during the morning 13 chars long) but its for sure
shorter than a lot of email addresses and for sure a unique ID.

Also, you would not have problems if more than 1000 users.

Hope this helps

Mauricio Lairet P.


----- Original Message -----
From: "Nikola Knezevic" <[EMAIL PROTECTED]>
To: "Perl Users Mailing List" <[EMAIL PROTECTED]>
Sent: Monday, March 05, 2001 3:30 PM
Subject: creating unique ID's


> 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
>

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to