Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Firstly, most of the code was donated by "Graff", however, I want to make it available to all as it works very well.

I'm glad to see you have something working (after such a length development phase ;) But I'd just like to clarify that, at least in terms of raw byte count, I did not write "most of the code" posted above. I just provided the  while (<DATA>) loop, the following "for" loop, and the "trace_down" sub.

I think the post could be a more interesting contribution, and more people could find it useful, if that portion of your script were abstracted away from the database stuff. The basic premise is:

  • Read a file containing an unsorted list of "child/parent" records (one per line), where a child value in one record might be the parent value in one or more other records scattered throughout the list.

  • Populate a "node" hash structure, keyed by the string values found in each record, to keep track of parent and child relations among the strings.

  • Output the records in sorted order, so that for any string value that appears as both "child of" and "parent of" other values, the record containing its "child of" relation is first.

So as a general-purpose function, the while loop and for loop should be in a subroutine, whose parameters might be: input file handle, output file handle, maybe a string to use as the split regex. That and the "trace_down" sub could go into a "SortTree.pm" module, or something to that effect, to make it easier to re-use.

As for the database stuff you've posted here, it's fine that it works for you, but I expect anyone else would just have to scrape it off, because it really only works for you. Also, it's not clear to me how or why the contents of the "resultsfile" (from the DB query) end up as pipe-delimited. Is that some sort of default setting on your database server, or in Win32::SqlServer?

One last nit-pick -- you could replace all this:

my @TimeArray = localtime(time); my $year = sprintf ("%04d",$TimeArray[5]+1900); my $monthasnum = sprintf ("%02d",$TimeArray[4]+1); my $day = sprintf ("%02d",$TimeArray[3]); my $hour = sprintf ("%02d",$TimeArray[2]); my $minute = sprintf ("%02d",$TimeArray[1]); my $datestamp = "$year"."_"."$monthasnum"."_"."$day"."_"."$hour" ."_" +."$minute" ;
with this:
use POSIX; my $datestamp = strftime( "%Y_%m_%d_%H_%M", localtime );
Gotta love POSIX... (updated to add link to POSIX man page)

In reply to Re: Building a data Hierarchy by graff
in thread Building a data Hierarchy by SlackBladder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (8)
As of 2024-04-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found