complete_tree.pl 891 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl
  2. # Don't know exactly what this is but it's probably a good idea.
  3. use 5.006;
  4. use strict;
  5. use Data::Dumper;
  6. sub add_parents ($) {
  7. my $elt = shift;
  8. if (exists $elt->{'contents'}) {
  9. foreach my $child (@{$elt->{'contents'}}) {
  10. $child->{'parent'} = $elt;
  11. add_parents ($child);
  12. }
  13. }
  14. if (exists $elt->{'args'}) {
  15. foreach my $child (@{$elt->{'args'}}) {
  16. $child->{'parent'} = $elt;
  17. add_parents ($child);
  18. }
  19. }
  20. }
  21. my $in_file = $ARGV[0];
  22. my $tree_stream;
  23. print "Getting tree...\n";
  24. $tree_stream = qx(./parsetexi $in_file 2>/dev/null);
  25. print "Got tree.\n";
  26. my $VAR1;
  27. print "Reading tree...\n";
  28. eval $tree_stream;
  29. print "Read tree.\n";
  30. print "Adjusting tree...\n";
  31. add_parents ($VAR1);
  32. print "Adjusted tree.\n";
  33. $Data::Dumper::Purity = 1;
  34. $Data::Dumper::Indent = 1;
  35. #my $bar = Data::Dumper->Dump([$VAR1], ['$VAR1']);
  36. #print $bar;