Hello all, I would appreciate advice on how to go about writing a Perl script solution to the following problem:

The Layout:
- There are several flat files, used as config files, that contain blocks of text similar to XML format.
- Each block starts with a "[" and ends with a "]" and in between contains configuration arguments such as a unique "ID" number, a "Start" and "Done" fields.
- The "Start" field has values that are files that must be present
- The "End" field has values of files that are created once the "Start" files are present

Example of flat file:
[ ID: 123 Start: /tmp/file.1 /tmp/file.2 /tmp/file.3 Done: /complete/success.1 /complete/success.2 ] [ ID: 456 Start: /complete/success.1 /complete/success.2 /tmp/file.3 Done: /complete/success.3 /complete/success.4 ] ... etc

What I am trying to do
I would like to parse through the file using Perl and find the file dependencies, recursively, that each "ID" has.
For example, ID 456 depends on the two files /complete/success.1 and /complete/success.2 that are from ID 123

What next?
I think that I would have to
- parse the file out and match between each block, that is, between each "[" and "]"
- save each block to a hash with the ID and then the Start/Done fields as keys and the values as the filenames
e.g.

$hash{123}{Start} => /tmp/file.1 => /tmp/file.2 => /tmp/file.3 $hash{123}{End} => /complete/success.1 => /complete/success.2
Then do I compare all the hash values to see which one matches to find what depends on what? That seems a bit complicated but I'm not sure if there is an easier way.
Could someone point me in the right direction with the logic or provide other solutions?


In reply to Parsing a file and finding the dependencies in it by legendx

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.