Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Pattern Identification

by BillKSmith (Monsignor)
on Oct 01, 2017 at 13:31 UTC ( [id://1200464]=note: print w/replies, xml ) Need Help??


in reply to Pattern Identification

The following form, suggested by the book "Perl Best Practices" (ISBN 0596001738), is easy to understand and maintain. If speed is truly important, it should be a candidate in your benchmark.
use strict; use warnings; sub string_type { $_ = shift; my $type # format ? type = /^\d{2}.\d{2}.\d{2}$/ ? 'date' : /^\d{2}.\d{2}.\d{4}$/ ? 'date' : /^[A-Z]{2}\d{9}[A-Z]{2}$/ ? 'Royal Mail Track & Trace code +' : /^\d{16}$/ ? 'visa card' : /^\d{13}$/ ? 'EAN-13 barcode' : 'unrecoginized string' ; if ($type eq 'EAN-13 barcode') { ... # Handle sub-types } return $type; }
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2026-03-13 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.