G'day Doozer,

If you're thinking about using the base number as a hash key, I assume it's unique. In which case, all of the numbers you've shown should match /${base}\d?$/; which they do:

Just a standard alias of mine:

$ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -MCarp::Always -E +'
$ perle ' my $base = "1231600014"; my @possibles = qw{ 012212316000140 01221231600014 2212316000140 1221231600014 221231600014 1231600014 }; my $re = qr{${base}\d?$}; for (@possibles) { if (/$re/) { say "$_ MATCH"; } else { say "$_ NO MATCH"; } } ' 012212316000140 MATCH 01221231600014 MATCH 2212316000140 MATCH 1221231600014 MATCH 221231600014 MATCH 1231600014 MATCH

That should get you started. I'm unsure on how you want to precede from here: look up dates from somewhere? determine a check digit somehow?

Your post seemed to suggest you knew the base code up-front. If not:

$ perle ' my @possibles = qw{ 012212316000140 01221231600014 2212316000140 1221231600014 221231600014 1231600014 }; my %re_map = ( 10 => qr{^(\d{10})$}, 12 => qr{^\d{2}(\d{10})$}, 13 => qr{^(?:(?:18|19|20|21|22)(\d{10})\d|\d{3}(\d{10}))$}, 14 => qr{^\d{4}(\d{10})$}, 15 => qr{^\d{4}(\d{10})\d$}, ); for (@possibles) { my $re = $re_map{+length}; /$re/ and say $1 // $2; } ' 1231600014 1231600014 1231600014 1231600014 1231600014 1231600014

Both of those pieces of code are just showing techniques: adapt, as necessary, to your specific needs.

— Ken


In reply to Re: Merging multiple variations of a serial number by kcott
in thread Merging multiple variations of a serial number by Doozer

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.