http://www.perlmonks.org?node_id=569593


in reply to Re: RFC: Business::CreditCard::Obscure
in thread RFC: Business::CreditCard::Obscure

You're using substr repetitively, but you don't need to.

print obscure('5555666677778888', 4, 2, '*'); sub obscure { my ($num, $tip, $tail, $char) = @_; my $repl_length = length($num) - $tip - $tail; substr($num, $tip, $repl_length) = $char x $repl_length; return $num; } __END__ 5555**********88

Looking at this again, I'm noting that this in production code should really make use of some data validation. Calling obscure() with a negative value for $tip would have some interesting results, for example. ;-)

Updates:

<radiant.matrix>
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet