David Gilden wrote:
Hello,

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.

Do you mean safe as in unique? Or do you mean safe because you are using a social security number which may be illegal in some places and could expose your customers to identity theft?



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!


#!/usr/bin/perl -w
#use strict;

$ss = '1234567890';
$lname = 'Gilden';
# $pkey  = substr($ss,length($ss)-4,length($ss)) .  substr($lname,0,3);
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A verbose way of writing:
             substr($ss,-4)


# 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";

If you want to do the same thing with the match operator:

my $ss = '09876543';
my $lname = 'Smith';

( $ss ) = $ss =~ /(.{4})$/;
( $lname ) = $lname =~ /^(.{3})/;

my $pkey = "$ss$lname";


Or using the substitution operator:

my $ss = '09876543';
my $lname = 'Smith';

$ss =~ s/.*(.{4})$/$1/;
$lname =~ s/^(.{3}).*/$1/;

my $pkey = "$ss$lname";


# Is there any advantage using =~ m/(\w){3}/ over substr method?

Not really. Of course you could use pack or unpack or sprintf instead. :-)



John
--
use Perl;
program
fulfillment

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