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
[ 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.
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.$hash{123}{Start} => /tmp/file.1 => /tmp/file.2 => /tmp/file.3 $hash{123}{End} => /complete/success.1 => /complete/success.2
In reply to Parsing a file and finding the dependencies in it by legendx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |