Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: RFC: Business::CreditCard::Obscure

by radiantmatrix (Parson)
on Aug 25, 2006 at 14:32 UTC ( #569593=note: print w/replies, xml ) Need Help??

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


  • 2006-08-25 : Added thoughts about data validation

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://569593]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2021-05-12 08:18 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (125 votes). Check out past polls.