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.

In reply to RFC: Business::CreditCard::Obscure by kwaping

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.