Greetings,
I am working on a script that searches through files and verifies that naming conventions within the files follow certain standards. The names that I am checking are in the form aa_bb_cc_dd, of varying length and there may be numbers appended to some of the segments as here, aa_bb123_cc_dd. They may also take the form aa_cc, or cc_ee123_jj. bb doesn't have to immediatly follow aa, it just can't be before it. I have set up a definition file that has 21 "tiers". The def file looks something like:
aa = 0 ab = 0 bb = 1 bc = 1 cc = 2 cd = 2
and so on. I am creating a hash from this file in the form $hash{aa} = 0. I then split each line from the file that I'm checking:
@segments = split("_", $line);
and make sure that
$hash{$segment[0]} < $hash{$segment[1]}
and so on. First, does anyone have a better way of doing this? Second, is there a way to pattern match the keys of the hash without cycling through all the keys for each line of the file being checked? The reason I would like to do this is that the numbers that can be appended to a given segment are subject to change, and this means a lot of maintenance of the definition file, which I would like to avoid. I would like to do something like have a key be ab\d+ and be able to match that key to ab123, is this possible?

In reply to hash keys and regex by state-o-dis-array

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.