in reply to I think regex Should Help Here... but How!?
Many thanks for the postings, folks.. and profuse apologies for the somewhat vague requirements -- I really shouldn't try to be overly creative at (what is for me) such a late hour...!
Maybe things would be clearer if step back some and explain the original issue...
I have some records where one of the fields is a category, of sorts. It can be a simple, single item ('comp') or it can be a composite ('muse.new').
I start doing my processing by running though the complete set of records (in the 100s of 100+ character records, so not large), noting the record category in a hash (and storing other data besides). As a by-product, I might note that category strings can range from 1 to, say, 3 dot-delimited elements; for example, the formats of the categories might match one of 'aaa' (no dots), 'bbbb.cc' (one dot) and 'dd.eeee.f' (two dots).
Now, let's define a 'level' as the number of 'words' in the category (as determined by the dot delimiters). So, a 'Level 1' category would include 'comp' and 'muse' but would NOT include '' (null) nor 'comp.hw'.
Similarly, a 'Level 2' category would include 'comp.hw' and 'muse.new' but would NOT include 'garden.hw.new' nor 'magic.ancient.toys.tin'.
...and so it goes through all the 'levels' that I'd found in my initial pass through all the data records.
So, in some sort of pseudocode, we might progress like:-
j = 1 while (j <= 3) hash = (null) test list = (null) for each item in master category list if category is a 'Level j' add category to test list endif endfor for each data record get record category, record data for each test category if record category matches test category at level 'j' hash{test category} += record data endif endfor endfor foreach key in hash output hash(key) endfor j += 1 endwhile
Thus, we'd end up with an output that is something like:
At Level 1: comp = 100 (includes comp, comp.hw, comp.sw...) muse = 200 (inlcudes muse, muse.new, ...) At Level 2: comp.hw = 100 (includes comp.hw, NOT comp...) comp.sw = 200 (includes comp.sw, comp.sw.old, comp.sw.new...) ...
Does that make things clearer?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I think regex Should Help Here... but How!?
by AnomalousMonk (Archbishop) on Feb 16, 2014 at 00:49 UTC | |
by ozboomer (Friar) on Feb 16, 2014 at 03:37 UTC | |
by AnomalousMonk (Archbishop) on Feb 16, 2014 at 14:50 UTC | |
by AnomalousMonk (Archbishop) on Feb 16, 2014 at 20:55 UTC |