http://qs321.pair.com?node_id=11145836


in reply to Merging multiple variations of a serial number

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