in reply to Parsing a file and finding the dependencies in 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 ]
|
|---|