I guess I'm fumbling around for a good way to determine if I'm at a higher or lower level.<div><br></div><div>The best I can come up with is to test each type and assign a number like:</div><div><br></div><div><pseudo_code></div>

<div>$level;</div><div>if ($index     == "upper roman") { $level = 0}</div><div>elsif ($index == "lower alpha") {level = 1}</div><div>elsif ($index == "lower roman" {$level = 2}</div><div>else ($index == "decimal" {$level = 3}</div>

<div><br></div><div>Then do math against the previous level </div><div>i.e.  $current_level - $previous_level</div><div>negative = move up to parent (n times)</div><div>equal = sibling</div><div>positive = child</div><div>

<br></div><div>to determine how to either recurse or how many calls to Tree::DAG_Node</div><div><br></div><div>It just seems brittle</div><div><br><br><div class="gmail_quote">On Wed, Mar 16, 2011 at 11:48 AM, David Young <span dir="ltr"><<a href="mailto:davidy@nationalcycle.com">davidy@nationalcycle.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">>> 2) how to traverse the array without knowing my indexes, i.e. go one level up, go one level down</div>

<div><br><div>Should be pretty easy to implement using recursion.  If you come across a new line and it's a different "type" of prefix, recurse down if it looks like a lower level (a simple conditional or regex test), otherwise "return" to the previous level and let that level continue walking the hierarchy.</div>



<div><br></div><div>ydy</div><div><br clear="all"><b>David J. Young</b><br><span style="font-size:x-small">IT Director<br><span style="font-size:small"><b><a href="http://www.nationalcycle.com" target="_blank"><img></a> National Cycle, Inc.</b></span><br>



<b>office +1-</b>708-343-0400 x103</span><div><span style="font-size:x-small"><a href="mailto:davidy@nationalcycle.com" target="_blank">davidy@nationalcycle.com</a></span></div><br>
<br><br><div class="gmail_quote"><div><div></div><div class="h5">On Wed, Mar 16, 2011 at 11:31 AM, Jay Strauss <span dir="ltr"><<a href="mailto:me@heyjay.com" target="_blank">me@heyjay.com</a>></span> wrote:<br></div>

</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">

Hi,<div><br></div><div>I need to build a hierarchy out of some data to load into a RDBMS.  The data looks like below.  I need to convert it to more like:</div><div><br></div><div>code, desc, parent_code</div><div><br></div>





<div>(where code is like "193200000X")</div><div><br></div><div>I'm struggling.</div><div><br></div><div>I think I could do this in a rigid manner by saying I have 4 indexes or levels:</div><div>upper case roman</div>





<div>lower case alpha</div><div>lower case roman</div><div>numeric</div><div><br></div><div>and keeping track where I am, and I the parent one level above.</div><div><br></div><div>I'd like to do it flexibly, without having to know how many levels in advance (I get similarly structured data with # of levels and info from time to time).  </div>





<div><br></div><div>But I don't know:</div><div><br></div><div>1) whats the best structure for this (I'm thinking an array of arrays)</div><div>2) how to traverse the array without knowing my indexes, i.e. go one level up, go one level down</div>





<div><br></div><div>Can anyone suggest ways to skin this cat?</div><div><br></div><div>Thanks</div><div>Jay</div><div><br></div><div><br></div><div><div>I.<span style="white-space:pre-wrap">  </span>Individual or Groups (of Individuals)</div>





<div>a.<span style="white-space:pre-wrap">        </span>Group  </div><div>i.<span style="white-space:pre-wrap">        </span>Multi-Specialty  - 193200000X</div><div>ii.<span style="white-space:pre-wrap"> </span>Single Specialty  - 193400000X</div>





<div>b.<span style="white-space:pre-wrap">        </span>Allopathic & Osteopathic Physicians  </div><div>i.<span style="white-space:pre-wrap">      </span>Allergy & Immunology - 207K00000X</div>

<div>1.<span style="white-space:pre-wrap">        </span>Allergy - 207KA0200X</div><div>2.<span style="white-space:pre-wrap">   </span>Clinical & Laboratory Immunology - 207KI0005X</div><div>

ii.<span style="white-space:pre-wrap">  </span>Anesthesiology - 207L00000X</div><div>1.<span style="white-space:pre-wrap">    </span>Addiction Medicine - 207LA0401X</div><div>2.<span style="white-space:pre-wrap">        </span>Critical Care Medicine - 207LC0200X</div>





<div>3.<span style="white-space:pre-wrap">        </span>Hospice and Palliative Medicine - 207LH0002X</div><div>4.<span style="white-space:pre-wrap">   </span>Pain Medicine - 207LP2900X</div><div>

5.<span style="white-space:pre-wrap">   </span>Pediatric Anesthesiology - 207LP3000X</div><div>iii.<span style="white-space:pre-wrap">        </span>Clinical Pharmacology - 208U00000X</div><div>

iv.<span style="white-space:pre-wrap">  </span>Colon & Rectal Surgery - 208C00000X</div><div>v.<span style="white-space:pre-wrap">        </span>Dermatology - 207N00000X</div><div>1.<span style="white-space:pre-wrap">       </span>Clinical & Laboratory Dermatological Immunology - 207NI0002X</div>





<div>2.<span style="white-space:pre-wrap">        </span>Dermatopathology - 207ND0900X</div><div>3.<span style="white-space:pre-wrap">  </span>MOHS-Micrographic Surgery - 207ND0101X</div><div>
4.<span style="white-space:pre-wrap">   </span>Pediatric Dermatology - 207NP0225X</div>
<div>5.<span style="white-space:pre-wrap">        </span>Procedural Dermatology - 207NS0135X</div><div>vi.<span style="white-space:pre-wrap">   </span>Electrodiagnostic Medicine - 204R00000X</div>

<div>vii.<span style="white-space:pre-wrap">      </span>Emergency Medicine - 207P00000X</div></div>
<br></div></div>_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org" target="_blank">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br></blockquote></div><br></div></div>
<br>_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br></blockquote></div><br></div>