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?


In reply to Re: I think regex Should Help Here... but How!? by ozboomer
in thread I think regex Should Help Here... but How!? by ozboomer

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.