state-o-dis-array has asked for the wisdom of the Perl Monks concerning the following question:
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:
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:
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:aa = 0 ab = 0 bb = 1 bc = 1 cc = 2 cd = 2
and make sure that@segments = split("_", $line);
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?$hash{$segment[0]} < $hash{$segment[1]}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: hash keys and regex
by DamnDirtyApe (Curate) on Dec 23, 2004 at 18:53 UTC | |
by state-o-dis-array (Hermit) on Dec 23, 2004 at 19:06 UTC | |
Re: hash keys and regex
by Aristotle (Chancellor) on Dec 24, 2004 at 01:40 UTC | |
by state-o-dis-array (Hermit) on Dec 24, 2004 at 15:46 UTC | |
by Aristotle (Chancellor) on Dec 24, 2004 at 16:06 UTC | |
by state-o-dis-array (Hermit) on Dec 24, 2004 at 18:56 UTC | |
by Aristotle (Chancellor) on Dec 25, 2004 at 02:55 UTC | |
Re: hash keys and regex
by blazar (Canon) on Dec 26, 2004 at 13:37 UTC |
Back to
Seekers of Perl Wisdom