This is a very simple pure-Perl module that I thought might be CPAN-worthy (after refinement and POD, etc.). It takes a string input "cardnum" and replaces part of it with another character or string "replacement". The user can specify the replacement string as well as how many characters of the original string are left unchanged at both the "head" and "tail".
Comments are appreciated!
---
It's all fine and dandy until someone has to look at the code.
Comments are appreciated!
package Business::CreditCard::Obscure; use strict; use warnings; sub new { my ($pack,%in) = @_; my $hash = {}; $hash->{'cardnum'} = defined($in{'cardnum'}) ? $in{'cardnum'} : un +def; $hash->{'head'} = defined($in{'head'}) ? $in{'head'} : 0; $hash->{'tail'} = defined($in{'tail'}) ? -$in{'tail'} : -4; $hash->{'replacement'} = defined($in{'replacement'}) ? $in{'replac +ement'} : '*'; return bless $hash, $pack; } sub obscure { my ($check,%in) = @_; my $self = ($check eq __PACKAGE__) ? $check->new(%in) : $check; $self->{'cardnum'} = $in{'cardnum'} if ($in{'cardnum'}); $self->{'head'} = $in{'head'} if ($in{'head'}); $self->{'tail'} = - $in{'tail'} if ($in{'tail'}); $self->{'replacement'} = $in{'replacement'} if ($in{'replacement'} +); return "cardnum not found" unless (defined($self->{'cardnum'})); return "head not found" unless (defined($self->{'head'})); return "tail not found" unless (defined($self->{'tail'})); return "replacement not found" unless (defined($self->{'replacemen +t'})); my $cardnum = $self->{'cardnum'}; substr( $cardnum, $self->{'head'}, $self->{'tail'} ) =~ s/./$self->{'replacement'}/g; return $self->{'obscured'} = $cardnum; } 1;
---
It's all fine and dandy until someone has to look at the code.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: RFC: Business::CreditCard::Obscure
by perrin (Chancellor) on Aug 21, 2006 at 19:12 UTC | |
by radiantmatrix (Parson) on Aug 25, 2006 at 14:32 UTC | |
by perrin (Chancellor) on Aug 25, 2006 at 16:12 UTC | |
Re: RFC: Business::CreditCard::Obscure
by cees (Curate) on Aug 21, 2006 at 19:42 UTC | |
by izut (Chaplain) on Aug 21, 2006 at 20:02 UTC | |
Re: RFC: Business::CreditCard::Obscure
by izut (Chaplain) on Aug 21, 2006 at 18:11 UTC | |
by kwaping (Priest) on Aug 21, 2006 at 18:16 UTC | |
by izut (Chaplain) on Aug 21, 2006 at 18:22 UTC |
Back to
Meditations