Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Merging multiple variations of a serial number

by kcott (Archbishop)
on Jul 29, 2022 at 01:10 UTC ( #11145836=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-09-27 05:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (118 votes). Check out past polls.

    Notices?