#!/usr/bin/perl use strict; use warnings; my ($raw, @master, @sources); open LIST, 'slidelist'; while ($raw = ) { next if ($raw =~ /^\s*$/ or $raw =~ /^#/); # no comments or blanks next unless ($raw =~ /\.slide\.txt$/); chomp $raw; push(@master, "texts/$raw"); } close LIST; opendir DIR, 'texts'; @sources = map {"texts/$_"} grep {/\.slide\.txt$/} readdir DIR; closedir DIR; my (%seen_master, %seen_sources); for (@master) { $seen_master{$_} = 1; } for (@sources) { $seen_sources{$_} = 1; } my $subset_status = 1; for (@master) { unless (exists $seen_sources{$_}) { $subset_status = 0; last; } } unless ($subset_status) { my (%master_only); foreach (keys %seen_master) { $master_only{$_}++ if (! exists $seen_sources{$_}); } print "These files, though listed in 'slidelist', are not found in 'texts' directory.\n\n"; print " $_\n" for (keys %master_only); print "\nEdit 'slidelist' as needed and re-run script.\n"; exit (0); } my (%intersection, %difference); for (keys %seen_master) { $intersection{$_}++ if (exists $seen_sources{$_}); } for (keys %seen_sources) { $difference{$_}++ unless (exists $intersection{$_}); } my @unused = keys %difference; open UNUSED, ">unused"; print UNUSED "Files currently unused:\n"; if (@unused) { print UNUSED " $_\n" for (sort @unused); print "There are unused files; see 'unused'.\n"; } else { print UNUSED " [None.]\n"; print "There are no unused files.\n"; } close UNUSED;