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

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!
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.