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.


In reply to Grab everything not matched by regexp by Kerplunk

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.