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:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: RFC: Business::CreditCard::Obscure
by perrin (Chancellor) on Aug 25, 2006 at 16:12 UTC |