If there's a problem, I don't think it involves the grep operation in the code I suggested. In the "for" loop over top-level parents, the grep does not involve a regex match, and is not susceptible to "false-alarm" substring matches. It is only returning the keys for those elements in the %node hash that are not the children of other nodes. Hash key lookups are always based on exact matches -- "abc" does not match "abcd" as a hash key.
The two sample records you cited involve two child values having the same parent value, so if I understand what you've said so far, their ordering relative to each other should not matter. If that parent value happens to be the child in some other record, it would matter to have that other record output before these two.
Since you have pipe-delimited data, I'm assuming you've extracted the data from the older server into a text file, and you're reading from that file in order to sort it, which makes perfect sense. Of course, my code would need to be adjusted slightly for pipe-delimited input instead of space-delimited:
Apart from that, if there's still a problem, you would need to post a minimal demonstration -- a snippet like mine, including sufficient "real-world" data, that exhibits the problem, and perhaps some clarification as to how the actual output differs from the desired output.while (<DATA>) { chomp; my ( $c, $p ) = split /\|/; ... # update: also need to change the print statement in sub trace_down(): ... print "$kid|$$tree{$kid}{child_of}\n"; ...
In reply to Re^3: Perl modules or standard tools for searching hierachical data
by graff
in thread Perl modules or standard tools for searching hierachical data
by SlackBladder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |