To get you started, see the parser below. I generate two hash tables which are linked by the id number. One hash table translates any output file to the id number which produced it. The other hash translates id number into the input files which created it.

I haven't written any code to make a report, but I think that this is enough to travel backwards from an output fileA -> id, then id->inputfilesX, therefore output fileA depends upon inputfiles X. Those input files can be looked up to see where they came from, etc.

hope this provides fuel for thought. It could be that a different data structure is better than this, but at least it shows one way to get the parsing done.

Update: Added some printing code to make a basic report to show all files used to generate a particular output file.

#!/usr/bin/perl -w use strict; use Data::Dumper; my %id; my %done; my %record=(); while (<DATA>) { if (my $num = /\[/.../\]/) { my ($tag, @values) = split; @{$record{$tag}} = @values; if ($num =~ /E0/) { my ($id) = @{$record{'ID:'}}; @{$id{$id}} = @{$record{'Start:'}}; foreach (@{$record{'Done:'}}) { $done{$_}= $id; } %record=(); } } } print Dumper \%done; print Dumper \%id; foreach my $file (keys %done) { print "$file\n"; my %seen; print map{" $_\n"}grep{!$seen{$_}++}priorFiles($file); print "\n"; } sub priorFiles { my ($file) = @_; return() if !exists $done{$file}; my @prior = @{$id{$done{$file}}}; foreach (@prior) { push @prior, priorFiles($_); } return @prior; } =output %done shows the id number which produced each file $VAR1 = { '/complete/success.3' => '456', '/complete/success.2' => '123', '/complete/success.1' => '123', '/complete/success.4' => '456' }; %id shows the input files were used by the id $VAR1 = { '456' => [ '/complete/success.1', '/complete/success.2', '/tmp/file.3' ], '123' => [ '/tmp/file.1', '/tmp/file.2', '/tmp/file.3' ] }; #This is a basic listing..all files that affected the first file /complete/success.3 /complete/success.1 /complete/success.2 /tmp/file.3 /tmp/file.1 /tmp/file.2 /complete/success.2 /tmp/file.1 /tmp/file.2 /tmp/file.3 /complete/success.1 /tmp/file.1 /tmp/file.2 /tmp/file.3 /complete/success.4 /complete/success.1 /complete/success.2 /tmp/file.3 /tmp/file.1 /tmp/file.2 =cut __DATA__ [ 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 ]

In reply to Re: Parsing a file and finding the dependencies in it by Marshall
in thread 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.