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. ;-)


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

Replies are listed 'Best First'.
Re^3: RFC: Business::CreditCard::Obscure
by perrin (Chancellor) on Aug 25, 2006 at 16:12 UTC
    I know, I just don't like lvalue subtring. It might be faster, for people who aren't bothered by the way it looks.