David Gilden wrote: > 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. 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! > Thanks, > Dave > ( webmaster @ www.coraconnection.com / Ft. Worth, TX, USA) > > > #!/usr/bin/perl -w > #use strict; > > $ss = '1234567890'; > $lname = 'Gilden'; > # $pkey = substr($ss,length($ss)-4,length($ss)) . substr($lname,0,3); This > substr does what you want but only because of the size of the data. If you had a > larger field, you would get more digits as part of your key. What you are getting > for your substr is a length of 10 to pull, but you really only want 4 digits.
> # 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)})/); f you want the last four digits of the field, then /(\d{4})$/ will get the last four digits you want. > # $pkey = ($pkey =~ m/$lname{0,3}/;) > print "$pkey\n"; > > # Is there any advantage using =~ m/(\w){3}/ over substr method? substr will be faster so if doing a lot and have control over the input, then the substr would be the way to go. Wags ;) > > __END__ ******************************************************* This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ******************************************************* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>