David Gilden wrote:

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

Why not just:

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

$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}/;)

This might be one way:

    $pkey = join '', $ss =~ /(\d{4})$/, $lname =~ /(.{3})/;

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

No. Regular expressions are less efficient. substr() should better be used in this case.


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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