> Hello,
> 
> I am building a primary key for a database, and I guess the first
question would be 
> how safe is a key made from the last 4 digits of a social security num
and the first 
> 3 letters of the last name.  

I would guess not very, but I don't know what your target sample size
is.  I know there is a quick equation for this involving factorials of
10, and 26, but that hurts my head....  Not to mention you want to make
a primary key very fast, on some databases there may be limitations that
don't allow a non-integer field as the primary key, or it may slow them
down unnecessarily. I would create a primary key as an autoincrementing
integer, then just use your "unique" value as a regular key, this also
prevents worrying about collisions.

Now for the PERL question, I have substr. line working correctly.
> I wanted to try it with ReGrex,  but the syntax is escaping me. 
> Any pointers would appreciated!

Its 'Perl' or 'perl' but never PERL.

> Thanks,
> Dave
> ( webmaster @ www.coraconnection.com  / Ft. Worth, TX, USA) 
> 
> 
> #!/usr/bin/perl -w
> #use strict;
> 

Commenting this out means it can't help you, and many here might decide
not to either.

> $ss = '1234567890';
> $lname = 'Gilden';
> # $pkey  = substr($ss,length($ss)-4,length($ss)) .  substr($lname,0,3);

We don't really need the C<length> calls here, C<substr> is pretty smart.

my $pkey = substr($ssn, -4).substr($lname,0,3);


> # print  "$pkey\n";
> 
> $ss = '09876543';
> $lname = 'Smith';
> # this line is bad! -- trying to have the same functionality as the
substr line.
> $pkey = ($ss =~ m/\d{length($ss)-4}($ss{length($ss)})/);
> # $pkey = ($pkey  =~ m/$lname{0,3}/;) 
> print  "$pkey\n";
> 
> # Is there any advantage using  =~ m/(\w){3}/ over  substr method?
>

Its (most likely) slower. Does that count?  I believe the problem is
that you are attempting to call a function within a regex where you
aren't allowed.  But using two calls to length within a regex, along wit
h testing for proper capturing, not to mention the line noise, seems
very silly to me. KISS.
 
> __END__
> 
> 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to