C
cldmismgr
I have this little piece of code to replace all but the last 4 numbers
in a credit card number with *'s. Is there a better way to do this? I
tried using just a regex but everything I tried failed. For example
s/^[0-9]{9}/*/ replaced this first 9 digits with one *. The idea is to
replace each digit with an asterick and leave the last four digits
alone.
$st = "*";
$addr = '123456789012345';
$size = length($addr) - 4;
for ($i=0;$i < $size; $i++) {
$star .= $st;
}
print "$addr\n";
$addr =~ s/^[0-9]{$size}/$star/;
print "$addr\n$star\n";
Thanks for any comments or advice
Craig
in a credit card number with *'s. Is there a better way to do this? I
tried using just a regex but everything I tried failed. For example
s/^[0-9]{9}/*/ replaced this first 9 digits with one *. The idea is to
replace each digit with an asterick and leave the last four digits
alone.
$st = "*";
$addr = '123456789012345';
$size = length($addr) - 4;
for ($i=0;$i < $size; $i++) {
$star .= $st;
}
print "$addr\n";
$addr =~ s/^[0-9]{$size}/$star/;
print "$addr\n$star\n";
Thanks for any comments or advice
Craig