Kerplunk has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to parse information out of a large collection of directory names. This includes things like dates, status indicators, blah blah blah. It also includes product names, which are the data least easily picked out. An example would be "MMF - Pretendin Coarse L, Codes 0114, 6114, 7504 - FINAL - 07.10.15". The names include all the same kinds of information, but do not have a predictable internal structure.
My notion has been to use a switch with fall-through rules, thusly (edited in the interests of brevity):
switch ($folder) { case m/(do not use|not used|delete(d?))/i { $include = 0; DEBUG("This one shouldn't be included"); next; } case m/(FINAL|DRAFT)/ { ($status) = $folder =~ m/(FINAL|DRAFT)/; DEBUG("case 0 = the status is '$status'"); next; } case m/($m_dateMonth)\s\d{2,4}/i { ($date) = $folder =~ m/(($m_dateMonth)\s\d{2,4})/i; DEBUG("case 1 = the date is '$date'"); next; } case m/\(($m_regions)\)/i { ($region) = $folder =~ m/\(($m_regions)\)/i; DEBUG("case 2 = the region is '$region'"); next; } case m/(MMF|ANDA|NDA|IND)/i { ($applicationType) = $folder =~ m/(MMF|ANDA|NDA|IND)/i; DEBUG("case 4 = the application type is '$applicationType'"); next; } case m/(\d{2,3}-?\d{3,4})/ { ($applicationNumber) = $folder =~ m/(\d{2,3}-?\d{3,4})/; DEBUG("case 6 = the application number is '$applicationNumber' +"); next; } }
Whatever doesn't get matched will be the product name (and some extraneous bits I can dispose of without much fuss.) However, I'm unsure of how to get this unmatched substring.
Suggestions and criticism welcomed equally.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grab everything not matched by regexp
by jethro (Monsignor) on Feb 22, 2010 at 22:53 UTC | |
by Kerplunk (Acolyte) on Feb 23, 2010 at 14:03 UTC | |
|
Re: Grab everything not matched by regexp
by Xiong (Hermit) on Feb 23, 2010 at 19:29 UTC | |
by molecules (Monk) on Feb 23, 2010 at 19:52 UTC | |
by Kerplunk (Acolyte) on Feb 24, 2010 at 14:06 UTC | |
|
Re: Grab everything not matched by regexp
by Anonymous Monk on Feb 23, 2010 at 08:04 UTC |